MQTT
MQTT
MQTT
Show
Home > Communications > MQTT
MQTT
MQTT (Message Queueing Telemetry Transport) is a messaging protocol that runs over TCP/IP, with a publish - subscribe
structure.
Publish data:
- To a defined Broker according to a configured Topic. For example, the Topic may be Kiln; the messages can include
application data such as temperature or pressure.
Configuring MQTT
In order to implement MQTT, you
must first configure the Broker
Connections.
When you begin configuring MQTT, UniLogic automatically creates the MQTT General struct and the MQTT Statistics struct.
https://www.unitronicsplc.com/Download/SoftwareHelp/UniLogic_Knowledgebase/Communications/MQTT.htm 1/9
15/11/22, 16:06 MQTT
MQTT Process UINT32 These indicate the status of the UniStream - broker connection
Status
0 - MQTT Initialization in Progress
1- MQTT is running
2 - MQTT is in "Pause" mode
Acknowledged UINT32
Publications
Note that you can modify these parameters at run-time via the Ladder element Set Broker Configuration.
Name Definition
Name This is a name that you assign to the broker for your own reference, and that UniLogic will assign to the MQTT Broker Struct.
It has no significance in the MQTT protocol.
ID This is a unique ID# for this broker; you use this number to link Ladder element parameters to the broker.
Port By default, UniLogic uses the common MQTT port 1883; edit this if your application requires. The range is 1-655535.
Clean Session Clean Session determines the behavior of the broker if the connection to a subscriber is broken.
0 = the broker saves all subscription data and incoming messages for that subscriber, and sends them all at re-connection.
1 = the broker does not retain any subscription data; the Subscriber must re-subscribe
Client ID You can assign a unique Client ID, or leave it blank. In this event UniLogic generates an ID. Limited to 23 characters.
Last Will Topic In the event of disconnection, this is the last topic that will be published to the broker
(optional)
Last Will Message In the event of disconnection, this is the message that will be published to the broker, under the Last Will Topic.
(optional)
Keep Alive (seconds) This is the amount of time the broker will wait before determining that the connection is broker.
Connection Attempts If the connection is broken, this is the amount of time UniStream will attempt to reconnect with a broker
Interval (seconds)
MQTT/SSL -- No Server Authentication: with this option, a secured encrypted connection is set up but neither the
broker nor UniStream is required to provide authentication.
MQTT/SSL -- CA certificate Only – the client will be prompted to provide a certificate file matching the broker's;
UniStream will require a valid certificate from the broker.
MQTT/SSL -- CA Signed Server certificate: the broker is required to provide a certificate issued by a known authority.
A list of such certificates is included in UniStream and updated at intervals.
https://www.unitronicsplc.com/Download/SoftwareHelp/UniLogic_Knowledgebase/Communications/MQTT.htm 2/9
15/11/22, 16:06 MQTT
Broker Struct
When you add a broker, UniLogic automatically creates a supporting struct. Note that these parameters are read-only.
Session Present Bit Indicates whether the broker already has a persistent session of the client from previous
interactions.
Return Code UINT8 This indicates the status of the UniStream - broker connection
0 - Connection accepted
1 - Connection refused, unacceptable protocol version
2 - Connection refused, identifier rejected
3 - Connection refused, server unavailable
4 – Connection refused, unknown user name or password
5 – Connection refused, not authorized
Subscription Configuration
This determines the topics on which UniStream will receive messages
Name Definition
Name This is a name that you assign to the subscription for your own reference, and that UniLogic uses to identify the
subscriptions. It has no significance in the MQTT protocol.
ID This is a unique ID# for this subscription; you use this number to link Ladder element parameters to the
subscription.
Topic This is the name of the topic that UniStream is subscribing to. It is a fixed string of up to 256 characters that
can contain wildcards.
Data UniStream stores the incoming message into the linked data tag; you may also link a buffer or a struct.
Quality of Service Quality of Service is a feature of the MQTT protocol that controls retransmission
Level Definition
0 Message is sent once. Reception is not acknowledged.
Buffered Mode Select this to cause the UniStream to save a queue of messages published on this topic.
Note that this means that, after UniStream receives a message, you must reset the Message Received bit in the
Subscription's struct in order to receive the next message in the queue.
If you do not select Buffered Mode, UniStream will simply accept messages as they arrive.
Subscribe at Boot This causes UniStream to automatically subscribe to the topic at Power-up.
Time
Format Click on the field to select whether the data will be interpreted as Raw Data (bytes), or according to JSON
format.
https://www.unitronicsplc.com/Download/SoftwareHelp/UniLogic_Knowledgebase/Communications/MQTT.htm 3/9
15/11/22, 16:06 MQTT
Subscription Struct
When you add a subscription, UniLogic automatically creates a supporting struct. Note that these parameters are read-
only.
Subscribed Status UINT8 Indicates if the subscription is successful, according to the Quality of Service selected
- 0 – success – Max QoS 0
- 1 – Success – max QoS 1
- 2 – Success – max QoS 2
- 128 – Failure
Message Received
Bit Turns ON each time a message arrives to the CPU.
(Received bit)
If Buffered Mode is selected, the user must reset this bit to enable UniStream to receive the
next message in the queue.
Last Message in String This is the last message received by UniStream on the topic
Topic
Last Message UINT32 UTC time stamp, indicating when the last message was received.
Received Time
Publication Configuration
This determines the topics on which UniStream will send messages.
You can create Periodic and Aperiodic messages. Periodic messages are published according to a time period set in the
configuration
Name Definition
Name This is a name that you assign to the Publication for your own reference, and that UniLogic uses to identify the
subscriptions. It has no significance in the MQTT protocol.
ID This is a unique ID# for this Publication; you use this number to link Ladder element parameters to the
Publication .
Topic This is the name of the topic that UniStream is subscribing to. It is a fixed string of up to 256 characters that
can contain wildcards.
Data UniStream stores the incoming message into the linked data tag; you may also link a buffer or a struct.
Quality of Service Quality of Service is a feature of the MQTT protocol that controls retransmission
Level Definition
0 Message is sent once. Reception is not acknowledged.
Retain Flag Selecting this notifies the broker to retain the last message in a topic. If a subscriber is off-line when the
message is received, and Retain Flag is selected, the broker will send the message when the connection is
restored.
https://www.unitronicsplc.com/Download/SoftwareHelp/UniLogic_Knowledgebase/Communications/MQTT.htm 4/9
15/11/22, 16:06 MQTT
Format Click on the field to select whether the data will be interpreted as Raw Data (bytes), or according to JSON
format.
Broker Received This turns ON after a broker receives a publication. Reset by user.
Subscribe to Topic
Parameter Name
A Select the subscription ID of the topic to subscribe to
Subscribe All
Parameter Name
A Select the ID of the broker to subscribe to, to receive all
Topics published by that broker
Unsubscribe Topic
Parameter Name
A Select the subscription ID of the topic to unsubscribe from
Connect Broker
Parameter Name
A Select the broker ID to connect to
https://www.unitronicsplc.com/Download/SoftwareHelp/UniLogic_Knowledgebase/Communications/MQTT.htm 5/9
15/11/22, 16:06 MQTT
Disconnect Broker
Parameter Name
A Select the broker ID to connect to
Parameter Name
A Select the ID of the Publication to send
Parameter Name
A Select the ID of the Publication to send
The Ladder functions Get/Set Broker Configuration require you to use a struct Data type called MQTT Broker Configuration.
Parameter Name
A Select the ID of the Broker you want to get the
configuration from
Parameter Name
A Select the ID of the Broker you want to send the
configuration to
https://www.unitronicsplc.com/Download/SoftwareHelp/UniLogic_Knowledgebase/Communications/MQTT.htm 6/9
15/11/22, 16:06 MQTT
Name Definition
IP /URL Enter the IP address or .url of the broker
Port By default, UniLogic uses the common MQTT port 1883; edit this if your application requires. The range is 1-655535.
Clean Session Clean Session determines the behavior of the broker if the connection to a subscriber is broken.
0 = the broker saves all subscription data and incoming messages for that subscriber, and sends them all at re-connection.
1 = the broker does not retain any subscription data; the Subscriber must re-subscribe
Client ID You can assign a unique Client ID, or leave it blank. In this event UniLogic generates an ID. Limited to 23 characters.
Last Will Topic In the event of disconnection, this is the last topic that will be published to the broker
(optional)
Keep Alive (seconds) This is the amount of time the broker will wait before determining that the connection is broker.
Connection Attempts If the connection is broken, this is the amount of time UniStream will attempt to reconnect with a broker
Interval (seconds)
Clean Session Flag Clean Session determines the behavior of the broker if the connection to a subscriber is broken.
The Ladder functions Get/Set Publication Configuration require you to use a struct Data type called MQTT Publication
Configuration.
Parameter Name
A Select the ID of the Publication you want to get the
configuration from
Parameter Name
A Select the ID of the Publication you want to send the
configuration to
Retained Flag Signifies broker behavior, whether the broker retains the last message in a topic.
https://www.unitronicsplc.com/Download/SoftwareHelp/UniLogic_Knowledgebase/Communications/MQTT.htm 7/9
15/11/22, 16:06 MQTT
Payload format 0 - Raw data,
1 - JSON
Set Publication State
Parameter Name
A Select the ID of the Publication to Enable/Disable
B 0= Enable 1=Disable
Get/Set Subscription Configuration
The Ladder functions Get/Set Subscription Configuration require you to use a struct Data type called MQTT Subscription
Configuration.
Parameter Name
A Select the ID of the Subscription you want to get the
configuration from
Parameter Name
A Select the ID of the Subscription you want to send the
configuration to
MQTT Pause/Start
Status Messages, MQTT Ladder Functions
Code Message
0 Success
https://www.unitronicsplc.com/Download/SoftwareHelp/UniLogic_Knowledgebase/Communications/MQTT.htm 8/9
15/11/22, 16:06 MQTT
1 Accepted
2 In progress
-1 Configuration Error. Check the values you are trying to assign and run the command again.
-3 Contact support
-4 Pause required. Before running any MQTT "Set" Ladder Operation, you must use a Pause MQTT function.
-7 You cannot run the function MQTT Set Publication State using the ID of a Publication configured as Aperiodic.
-8 You cannot run the function MQTT Send APeriodic using the ID of a Publication configured as Periodic.
-10 Broker Error. Check the Status Messages for this broker in Broker Struct > Return Code
-11 Subscription Error. Check the Status Messages for this Subscription in Subscription Struct > Subscription Status.
-12 Publication Error. Check the Status Messages for the linked broker in Broker Struct > Return Code, and republish.
https://www.unitronicsplc.com/Download/SoftwareHelp/UniLogic_Knowledgebase/Communications/MQTT.htm 9/9