Skip to content

Subscriptions

Subscriptions allow the HCC2 to POST tag topic updates to your application when they become available. The Python application must start a server that listens and responds to HTTP POST methods of SimpleMessage JSON objects.

Using the Subscriptions class within [services\subscriptions.py] each new subscription will:

  • Allocate a new TCP port (14000-14100).
  • Establish a subscription with the HCC2 Rest Server.
  • Start a Flask server listening for the callback URI.

Subscription data will be packed as a SimpleMessage object and put into a FIFO queue.

Usage

# 1) Subscribe to a tag topic
Subscriptions.subscribe("liveValue.diagnostics.this.io.0.digitalIoIn.ch1.")

# 2) Use various methods to receive data
# Get next value from queue
di1_state_message = Subscriptions.active["liveValue.diagnostics.this.io.0.digitalIoIn.ch1."].get()

# Get latest value discarding older values from queue
di1_state_message = Subscriptions.active["liveValue.diagnostics.this.io.0.digitalIoIn.ch1."].latest()

# 3) Unpack message
if di1_state_message is not None:

  di1_state_value = di1_state_message.value
  di1_state_quality = di1_state_message.quality
  di1_state_timestamp = di1_state_message.timeStamp

Subscriptions Setup

External PC Program

Ensure your development PC's IP address matches the value defined as app_ip_override in [config.json].

"network": {
  "rest_ip_override": "172.17.2.100", <-- HCC2 IP Address
  "app_ip_override": "172.17.2.75" <-- Dev Station IP Address
},
Local Image

Configure the inbound firewall settings to allow the subscription port range. Local Image

Docker Container Program

The Docker YML file will need ports 14000 - 14100 exposed for subscriptions to work. An example docker compose file:

---
version: '3.7'

services:
  samplePythonApp:
    image: samplepythonapp:v1.0.0
    container_name: samplePythonApp
    restart: on-failure
    expose:
    - 14000-14100
    volumes:
    - samplePythonApp_vol:/app/data:rw
    networks:
    - edgenet
    environment:
      LOG_LEVEL: info
    tmpfs:
    - /temp:uid=5678,gid=5678

networks:
  edgenet:
    name: edgenet

volumes:
  samplePythonApp_vol:
    name: samplePythonApp_vol

...