MQTT Client 2
MQTT Client 2
MQTT_Client_2
Version: 2.0
2. Important Information
The IIOT_Library_4 must be downloaded separately to this library to allow functionality of this library.
* This issue will be fixed in a future version*
There is a maximum of 100 publish and subscribe blocks allowed, and the more blocks that are used the
maximum rate of publishing messages will decrease.
3. Change Notes
Library Library PLCnext Change Notes Supported
Version Build Engineer PLC
Version
1 20220307 >= 2022.0.2 LTS Initial Release AXC F 1152
AXC F 2152
AXC F 3152
1.1 >= 2022.0.2 LTS New inputs for additional AXC F 1152
connection options, bug fixes AXC F 2152
AXC F 3152
2.0 >= 2023.0 LTS New inputs for additional AXC F 1152
MQTT brokers, Azure block AXC F 2152
created to simplify Azure AXC F 3152
communication, updated
packet sizes to library
maximum, upgraded to 2023.0.
4. Function Blocks
Function Block Description Ver Supported Articles License
5. MQTT_Client_3
The MQTT_Client_3 function block connects to an MQTT broker (local or internet based) and allows publishing and
subscribing to topics on that broker.
This Function Block may only be called one time, if called more than once this will cause unknown errors.
6. MQTT_Publish_1
The MQTT_Publish_1 function block publishes data to the MQTT Broker when connected.
8. JSON_Add_Object_1
The JSON_Add_Object_1 function block either creates a JSON or adds a new JSON object to an existing JSON.
9. JSON_Extract_Object_1
The JSON_Extract_Object_1 function block extracts a JSON object from a JSON string.
10. MQTT_Azure_1
The MQTT_Azure_1 function block is used to set all settings required for connecting to Azure. The only inputs
required to connect is the certificates and (optional) private key password.
To create larger payloads, the JSON_Add_Object blocks must be connected together, as shown in the
image below. Once the first object is added and the xComplete bit goes high, the next object can be
added and so on. Once the final object is added it can be attached to the MQTT_Publish to send.
The image above will send a message of : {“Temperature”: “70.50535”, “Count”: “13”}
Appendix 2: Using the JSON_Extract_Object_1 function block
with MQTT_Subscribe_1
This block connects directly to a MQTT_Subscribe block and extracts the specified object. This block will
only output all values as a string, so conversion is necessary. Below is an example of how to extract
objects from a JSON payload.
Extraction code:
Application Examples
Multiple application examples are included in the download of this library. It is located here:
MQTT_Client_2>Files>Examples