MQTT is a messaging protocol: messages are published to individual topics to a broker. Other clients that have subscribed to the corresponding topics receive these messages forwarded by the broker.
In addition, the current version MQTT 5 offers some enhancements that are utilized in the following protocol, notably the Message Expiry Interval for retained messages and the Response Topic header.
An MQTT broker is used to connect one or more PLCs (or similar data sources) to a HELIO Runtime, which in turn communicates with one or more HMIs via WebSocket.
MQTT MQTT WebSocket
+-------+ +-------+
| PLC 1 |---\\ +--------+ +-----------+ /------| HMI 1 |
+-------+ \\----| MQTT | | HELIO |-----/ +-------+
| Broker |-------| Runtime |
+-------+ /---| | | |-----\\ +-------+
| PLC 2 |----/ +--------+ +-----------+ \\------| HMI 2 |
+-------+ +-------+
A PLC can use the MQTT protocol to provide the following data to HELIO:
Variables
Variables, i.e. their current values, can be subscribed to by the Helio App Server.
Methods
Methods can be called by the HELIO Runtime (with input and output values).
Messages
Messages (alarms/events) can be received and acknowledged by the HELIO Runtime.
This example shows you how to publish messages so that the will be picked up by HELIO and can be used in your HMI. All examples assume that you’re running a local Mosquitto broker. (Note: Other broker’s will also work but their command syntax will differ.)
mosquitto_pub -r -D publish message-expiry-interval 3600 -t 'plc/plc1/meta' -m '{"version":1,"name":"PLC 1"}'
mosquitto_pub -r -D publish message-expiry-interval 3600 -t 'plc/plc1/variable/meta/test/gauge' -m '{"version":1,"name":"Gauge","type":"Real"}'
mosquitto_pub -r -D publish message-expiry-interval 3600 -t 'plc/plc1/variable/value/test/gauge' -m '50'
To check if this worked correctly, run this command:
mosquitto_sub -t "#" -v -W 1 --retained-only