IotMqttv5LastWillSample

Sample for the use of MQTTv5 UserProperties

The communication to an MQTT broker using MQTTv5 is shown in this sample. In particular, the LastWill mechanism of MQTTv5 is demonstrated. As a prerequisite, the message broker used must support MQTTv5. The basic flow of the sample is as follows:

The following code snippet once again shows the relevant part for specifying the LastWill message, as well as the associated properties. This code position is used for the initialization (only once) of the connection parameters.

fbMqttClient.stWill.sTopic := 'MyLastWillTopic';
fbMqttClient.stWill.sContentType := 'MyContentType';
fbMqttClient.stWill.eQoS := TcIotMqttQoS.ExactlyOnceDelivery;
fbMqttClient.stWill.fbPayload.SetData(ADR(sLastWillMsg), SIZEOF(sLastWillMsg));
fbMqttClient.stWill.fbUserProperties.AddUserProperty('MyFirst', 'UserProperty');

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),
Tc2_Utilities (>= v3.4.4.0)