OnMqtt5Message

Callback method

OnMqtt5Message 1:

This method must not be called by the user. Instead, the function block FB_IotMqtt5ClientBase can be used to derive information and overwrite this method. While the Execute() method is called, the responsible TwinCAT driver can call the OnMqtt5Message() method in the event of new incoming messages. In the event of several incoming messages the callback method is called several times, once per message. This must be taken into account when the method is implemented.
The use of the callback method is also explained in the sample IotMqttSampleUsingCallback.

Syntax

METHOD OnMqtt5Message : HRESULT
VAR_IN_OUT CONSTANT
    topic    : STRING;
END_VAR
VAR_INPUT
    payload  : PVOID;
    length   : UDINT;
    qos      : TcIotMqttQos;
    pProps   : POINTER TO MqttPublishProperties;
    pReq     : POINTER TO MqttRequestProperties;
    repeated : BOOL;
END_VAR

OnMqtt5Message 2: Return value

Name

Type

Description

OnMqtt5Message

HRESULT

The return value of the method should be S_OK, if the message was accepted. If the message is to be issued again in the context of the next Execute() call, the return value can be assigned S_FALSE.

OnMqtt5Message 3: Inputs

Name

Type

Description

payload

PVOID

Address for the payload of the received MQTT message

length

UDINT

Size of the payload in bytes

qos

TcIotMqttQos

"Quality of Service"

pProps

POINTER TO MqttPublishProperties

MQTT properties that may have been received with a message.

pReq

POINTER TO MqttRequestProperties

MQTT Request Properties, which may have been received with a message.

repeated

BOOL

If the user did not respond with S_OK to the last OnMqtt5Message() method call, the message is issued again in the context of the next Execute() call, and the parameter repeated is set. This indicates that the message was issued more than once.

OnMqtt5Message 4: Inputs/outputs

Name

Type

Description

Topic

STRING

Topic of the received MQTT message