FB_IotMqtt5Message
If the TwintCAT MQTT v5 client (FB_IotMqtt5Client) is used in combination with a message queue (FB_IotMqtt5MessageQueue), an MQTT message is represented by the FB_IotMqtt5Message function block. Incoming messages are collected by the message queue and made available to the user in the form of a such a function block instance.
The topic, the payload size and the "Quality of Service" parameter of the MQTT message are immediately available as Properties at the function block output. The topic and the payload can easily be evaluated or copied via the provided methods CompareTopic(), GetTopic() and GetPayload().
Message payload formatting Note that the data type and the formatting of the content must be known to the sender and receiver side, particularly when binary information (alignment) or strings (with or without zero termination) are sent. |
Size of an MQTT message The maximum size of an MQTT message to be received in the PLC depends on the hardware platform and should not exceed a few MB, even on higher-performance/larger platforms. The maximum possible size of a message can be set using the When using the MQTT Message Queue, it dynamically allocates new memory from the TwinCAT Router memory for new messages. |
Properties
Name | Type | Access | Description |
---|---|---|---|
bPayloadUtf8 | BOOL | Get | If TRUE, the payload is UTF-8 formatted text. |
bTopicAlias | BOOL | Get | Indicates whether the receive topic is an alias. |
eQoS | TcIotMqttQos | Get | "Quality of Service" of the MQTT message |
nCorrelationDataSize | UINT | Get | Size of the Correlation Data in bytes |
nMsgExpiryInterval | UDINT | Get | Specifies the expiration interval of the message in seconds. |
nPayloadSize | UDINT | Get | Size of the payload in bytes |
nSubIdCnt | UINT | Get | Indicates how many subscription identifiers were received. |
nUserPropertyCnt | UINT | Get | Number of existing user properties. These can be read using GetUserPropertyByIdx(). |
nUserPropertyCntLost | UINT | Get | Number of user properties discarded on reception. The cause can be an exceeding of the defined maximum number (see library parameter |
nTopicSize | UINT | Get | Size of the topic in bytes |
sContentType | STRING | Get | Content Type of the MQTT message If the original text is too large for this property, the GetContentType() method can be used to get the full text. |
Methods
Name | Description |
---|---|
Compares a specified topic with the topic in the MQTT message. | |
GetContentType() | Returns the Content Type of the MQTT message. |
GetCorrelationData() | Returns the Correlation Data of the MQTT message. |
GetResponseTopic() | Returns the Response Topic. |
Returns the content of an MQTT message. | |
GetSubIds() | Returns the Subscription Identifiers received for the MQTT message. |
Returns the topic of an MQTT message. | |
GetUserPropertyByIdx() | Returns the name and value of a UserProperty specified by its position (index) in the list. |
GetUserPropertyValueByName() | Returns the value of a UserProperty specified by its name. |
Strings in UTF-8 format The variables of type STRING used here are based on the UTF-8 format. This STRING formatting is common for MQTT communication as well as for JSON documents. In order to be able to receive special characters and texts from a wide range of languages, the character set in the Tc3_IotBase and Tc3_JsonXml libraries is not limited to the typical character set of the data type STRING. Instead, the Unicode character set in UTF-8 format is used in conjunction with the data type STRING. If the ASCII character set is used, there is no difference between the typical formatting of a STRING and the UTF-8 formatting of a STRING. Further information on the UTF-8 STRING format and available display and conversion options can be found in the documentation for the Tc2_Utilities PLC library. |
Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v3.1.4026.0 | IPC or CX (x86, x64, ARM) | Tc3_IotBase (>= v3.4.2.0) |