OnMqttMessage
Callback method

This method must not be called by the user. Instead, the function block FB_IotMqttClient can be used to derive information and overwrite this method. While the Execute() method is called, the responsible TwinCAT driver can call the OnMqttMessage() 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 OnMqttMessage : HRESULT
VAR_IN_OUT CONSTANT
topic : STRING;
END_VAR
VAR_INPUT
payload : PVOID;
length : UDINT;
qos : TcIotMqttQos;
repeated : BOOL;
END_VAR
Return value
Name | Type | Description |
---|---|---|
OnMqttMessage | 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. |
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" |
repeated | BOOL | If the user did not respond with S_OK to the last OnMqttMessage() 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. |
Inputs/outputs
Name | Type | Description |
---|---|---|
Topic | STRING | Topic of the received MQTT message |