FB_IotMqtt5SubscribeProperties

FB_IotMqtt5SubscribeProperties 1:

The function block allows the definition of different properties, which can be set when creating a subscription. This allows additional properties to be defined for a subscription and transferred from the client to the message broker.

General description of the Subscribe Properties:

Property

Description

No Local

When using MQTTv3, if a message is sent on the same topic that was also subscribed to, the sent message will be received again. By using this flag, you will not receive messages that have already been sent again.

Retained Message Control

Retain messages still work as with MQTTv3, but this flag adds options that define what should happen when retain messages are received.

Subscription Identifier

A numeric value used to identify a subscription.

User Properties

User Properties are key/value pairs that can transport additional metadata. These are managed via the function block FB_IotMqtt5UserProperties. The meaning of the UserProperties is not part of the MQTT5 specification and therefore application specific.

Syntax

Definition:

FUNCTION_BLOCK FB_IotMqtt5SubscribeProperties EXTENDS FB_IotMqtt5UserProperties
VAR_OUTPUT
    bError           : BOOL;
    hrErrorCode      : HRESULT;
END_VAR

FB_IotMqtt5SubscribeProperties 2: Outputs

Name

Type

Description

bError

BOOL

Becomes TRUE as soon as an error situation occurs.

hrErrorCode

HRESULT

Returns an error code if the bError output is set. An explanation of the possible error codes can be found in the Appendix.

FB_IotMqtt5SubscribeProperties 3: Properties

Name

Type

Access

Description

bNoLocal

BOOL

Get, Set

Specifies whether the NoLocal property should be set, see above.

bRetainAsPublished

BOOL

Get, Set

Specifies whether the retain flag of a publisher should remain set when a message is received.

nRetainHandling

BYTE

Get, Set

Specifies how to receive retain messages.

0: Retain messages are sent by the broker when the client subscribes. (Default behavior of MQTTv3)

1: Retain messages are sent by the broker only when the client subscribes if the subscription does not exist.

2: Retain messages are not sent by the broker when the client subscribes.

nSubId

UDINT

Get, Set

Numeric value for optional identification of a subscription.

pSubscribeProperties

POINTER TO MqttSubscribeProperties

Get

Pointer to an object of type MqttSubscribeProperties.

When calling FB_IotMqtt5Client.Subscribe() it is possible to pass this directly.

FB_IotMqtt5SubscribeProperties 4: Methods

Name

Description

SetSubscribeProperties

Allows you to set the Subscribe properties.

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)