MQTT Link
An MQTT Link connects your project to an MQTT broker. Each topic you subscribe to becomes a tag your rungs read, and an MQTT Publish instruction sends values out.
Connect to a broker
- In Project Explorer, click + next to I/O Links and choose MQTT.
- On Connection, type the broker address and port. 1883 is usual, or 8883 with Use TLS.
- If the broker needs a sign-in, type the username and password.
- Click Connect.
Add topics
- Stop the PLC and open the Topics tab.
- Under Subscribe, click Add, or Pick from active topics to choose from what the broker has now. For a JSON message, pick the field you want.
- Under Publish, click Add and name the tag, such as
CountMQTTforfactory/line1/count. - Put an MQTT Publish on a rung and point it at that tag.
Topic to tag
| On the broker | Tag in your project | In your rungs |
|---|---|---|
| factory/line1/temp | IO::MyBroker.Mqtt.Temp | Read it like any tag. It holds the last message. |
| factory/line1/count | IO::MyBroker.Mqtt.CountMQTT | MQTT Publish sends a value to it. |
| The connection | IO::MyBroker.Mqtt.Connected | On while the Link is connected. |
Good to know
- The Connection Service must be running on your computer. The status bar shows it.
- The password stays in the Connection Service. It is never saved in the project file.
- A topic for one tag cannot use
+or#. - OK turns on when a good message arrives, and off if the Link drops or a message does not fit the tag's type.
- Import… and Export… use a CSV with the columns Direction, Topic, Tag, Type and JSON Field.