Skip to main content

Library: MQTT Client SL

MQTT (Message Queuing Telemetry Transport) is an open-source IoT protocol which allows for the transmission of telemetry data as messages between devices. As a result, you can send messages from a CODESYS controller to an MQTT broker and subscribe to messages based on topics.

  • Devices always communicate via an MQTT broker.

    Example: Eclipses Mosquitto

  • Messages are sent and subscribed to based on topics. A topic corresponds to a path.

    Example: device1/temperature

  • Subscribing to messages is done by specifying a topic filter. Wildcards are also permitted (+ for one level, # for multiple levels).

  • The format of a message is not fixed. A JSON string or any data structure can be transmitted.

. Function blocks of the MQTT Client SL library:
  • Function block for establishing an MQTT link (MQTTClient)

  • Function block for sending messages (MQTTPublish)

  • Function block for subscribing to messages (MQTTSubscribe)

. Supported functions:
  • Publishing and subscription of messages based on MQTT V3.1.1 and MQTT V5.0

  • TLS encryption

  • Support of client certificates (transfer of a certificate handle)

  • Support of "Quality of Service'":

    0, 1, and 2 (QoS0, QoS1, QoS2) for last will, publisher, and subscriber

  • Data type of topics: WSTRING

  • Maximum size of a topic: 1024

  • The maximum package size and payload size can be configured by means of a parameter list.

  • Multitasking and multicore support

    MQTTClient, MQTTPublish, and MQTTSubscribe can each be run on different tasks or CPU cores.

  • "Last Will" messages (QoS0, QoS1, QoS2)

  • Wildcards (# and +)

  • MQTT or WebSocket

. Supported MQTT V5 functions:
  • Session Expiry

  • Message Expiry

  • Reason Code on All ACKs

  • Server Disconnect

  • Payload Format and Content Type

  • Request / Response

  • Shared Subscriptions

  • Subscription ID

  • Topic Alias

  • Flow Control

  • User Properties

  • Maximum Packet Size

  • Optional Server Feature Availability

  • Enhanced Authentication

  • Subscription Options

  • Will Delay

  • Server Keep Alive

  • Assigned ClientID

  • Server Reference

Message throughput

The maximum message throughput (number of messages/second, mps) depends on the hardware used, the message size, the QoS settings, and the configuration (parameter list MQTTParam, cycle time).

Example 1. Example of measurements

Configuration:

  • Local Mosquitto broker

  • Local CODESYS Control (1 publisher)

  • Local CODESYS Control (1 subscriber)

  • MQTTParam (default settings)

  • Message size: 1024 bytes

  • Cycle time: 1 ms

Result:

  • QoS0 => approx. 190 mps

  • QoS1 => approx. 130 mps

  • QoS2 => approx. 90 mps