IotMqttv5UserPropsSample

Sample for the use of MQTTv5 UserProperties

The communication to an MQTT broker using MQTTv5 is shown in this sample. In particular, the UserProperties 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 User Properties on a message to be sent.

fbPubProps.sContentType := sContentType;
fbPubProps.nMsgExpiryInterval := 7;
fbPubProps.bPayloadUtf8 := TRUE;
fbPubProps.ClearUserProperties();
FOR m:=1 TO 10 DO
  hrPropSet := fbPubProps.AddUserProperty(aUserName[m], aUserValue[m]);
  IF FAILED(hrPropSet) THEN
    EXIT;
  END_IF
END_FOR

In this sample, 10 User Properties whose key/value values are taken from the aUserName and aUserValue arrays are thus added to a message to be sent. The user properties are then passed to the message to be sent as input parameters to the Publish() method.

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)