FB_IotMqtt5MessageQueue

This function block provides a message queue for MQTT messages that are received with the function block FB_IotMqtt5Client. For this purpose, an instance is already provided at the output of FB_IotMqtt5Client. The function block operates based on the first in, first out principle (FIFO). It is possible that multiple MQTT messages are received within one PLC cycle and made available at the message queue.

During the program sequence, the property nQueuedMessages can be used to check whether and how many messages have been collected in the message queue. The Dequeue() method is used for removing messages from the FIFO queue. The oldest message is output first.

FB_IotMqtt5MessageQueue 1:

Size of the MQTT message queue

The maximum number of possible messages in the queue can be set via the parameter cMaxEntriesInMqttMessageQueue in the parameter list of the Tc3_IotBase library. The default value is 1000 messages. This value can usually be left unchanged, since prompt message processing is required in most cases.

The MQTT message queue allocates new memory space for new messages according to the topic and payload size. By default the maximum size of a message is limited to 100 kB, the size of the MQTT message queue is limited to 1000 kB. For special cases these values can also be adjusted in the parameter list.

FB_IotMqtt5MessageQueue 2: Properties

Name

Type

Access

Description

bOverwriteOldestEntry

BOOL

Get, Set

Here you can parameterize whether, when the queue is full, a newly received message should overwrite the oldest message. If yes (TRUE), the oldest message is lost. If no (FALSE), the reception of the new message will wait until the queue offers space.

A full queue is an unlikely case if the user ensures a speedy readout of the queue using the Dequeue() method.

nLostMessages

UDINT

Get

Returns the number of MQTT messages which had to be discarded completely.

Discarded MQTT messages can be caused by a full queue or by the total size of a newly received message being too large.

nMaxSizeOfMessage

UDINT

Get

Maximum size in bytes of all received MQTT messages, which should be received by the FB_IotMqtt5Client and stored in the FB_IotMqtt5MessageQueue.

If the maximum size specified with the library parameter ParameterList.cMaxSizeOfMqttMessage is exceeded, the message queue first attempts to save the message without user properties. If this size reduction is not sufficient, the MQTT message must be discarded completely.

nQueuedMessages

UDINT

Get

Outputs the number of MQTT messages currently collected in the queue.

The maximum possible number is set with the library parameter ParameterList.cMaxEntriesInMqttMessageQueue.

FB_IotMqtt5MessageQueue 3: Methods

Name

Description

Dequeue()

Removes an MQTT message from the queue.

ResetQueue()

Deletes all messages from the queue.

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)