MQTT

MQTT is a lightweight message transport protocol designed for IoT applications.

The MQTT Datasource object connects to MQTT brokers to subscribe to topics and receive the supplied message data.

mqtt communication

Configuration

The configuration of MQTT datasources is described in detail in the MQTT Datasource Object Guide.

Receiving Messages

With the MQTT Datasource configured and running, messages from the MQTT broker are received automatically for subscribed topics. The Sample Broker page illustrates how to check that messages are being received correctly, if you don’t have an existing MQTT broker available.

Sending Messages to the MQTT Broker

For sending a message to an MQTT Broker from the system, an MQTT Publisher IO-Item object is required.

Creating an MQTT Publisher IO-Item

To create an MQTT Publisher IO-Item …​

1 Right click on the Datasource MQTT Subscriber object in the I/O Model and select Admin  New to open the Create Object wizard.

2 In the Available Objects list, select External Interfaces > IO-Item MQTT.

3 In the Property Compounds list, select Common compound and enter an Object Name for the new IO-Item.
For this example use 'MQTT Publisher for Topic-1'

4 Also set the Item ID property to the same value as the Object Name.

5 Go to the MQTT Item Type section.

6 In the Topic property, specify the name of the topic to which this IO-Item is supposed to subscribe to. For this example set it to 'Topic-1'.

7 For Item Type select 'Publisher'.

8 Click Create to create the new IO-Item in the I/O Model.

The new IO-Item will appear in the I/O Model in red state. The state will turn green when the first message is successfully sent.

Sending messages from the IO-Item to the MQTT broker

Once the MQTT Publisher IO-Item has been created, it will send a message to the MQTT broker every time its value changes. To test this …​

1 Select the IO-Item in the I/O Model, open the Object Lens and double click the value in the Faceplate to open the Write Value dialog.

2 For the Type property, select 'String'. Then enter a message to the Value field. Finally click Write.

A new IO-Item will be created for the new Topic in the IO-Item since the Datasource was configured to accept all topics from the MQTT Broker, using the '#' wildcard for the Topic property in the Subscription Data compound.

3 Select this new IO-Item in the I/O Model and check the faceplate of the property panel. The value which you entered in the previous step should be displayed there.

Advanced Topics

Lua Callbacks

For implementing custom logic for the communication with the MQTT Datasource, see the Lua Callbacks page.

Sparkplug Protocol

For information about using the Sparkplug protocol with the MQTT Datasource, see the Sparkplug Protocol page.

Testing with a Sample Broker

If you do not have access to an MQTT broker for testing, you can use a sample broker. See the Sample Broker page for more information.