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.

Messages go from the broker to the Connection Service on this computer, then into your project as Link tags. MQTT Publish sends values the other way.MQTT brokerlocalhost : 1883factory/line1/tempfactory/line1/countConnection ServiceOn this computer. Keeps the password.Your projectReadIO::MyBroker.Mqtt.TempSendMQTT Publish → CountMQTTmessages inpublish out

Connect to a broker

  1. In Project Explorer, click + next to I/O Links and choose MQTT.
  2. On Connection, type the broker address and port. 1883 is usual, or 8883 with Use TLS.
  3. If the broker needs a sign-in, type the username and password.
  4. Click Connect.

Add topics

  1. Stop the PLC and open the Topics tab.
  2. 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.
  3. Under Publish, click Add and name the tag, such as CountMQTT for factory/line1/count.
  4. Put an MQTT Publish on a rung and point it at that tag.

Topic to tag

On the brokerTag in your projectIn your rungs
factory/line1/tempIO::MyBroker.Mqtt.TempRead it like any tag. It holds the last message.
factory/line1/countIO::MyBroker.Mqtt.CountMQTTMQTT Publish sends a value to it.
The connectionIO::MyBroker.Mqtt.ConnectedOn 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.

Related