MqttSubscribe – Subscribe to MQTT topic

Block SymbolLicensing group: MQTT
PIC

Function Description
This function block depends on the MQTT driver. Please read the MQTTDrv manual [19] before use.

The MqttSubscribe block subscribes to a topic on an MQTT broker and receives Publish messages on that topic through the connection established by the MQTTDrv driver.

The first parameter is the topic the block will subscribe to. MQTT protocol delivers Application Messages according to the Quality of Service (QoS) levels. Use the QoS parameter to set a different Quality of Service level. See the MQTT specification [20] for more details.

By setting the type parameter of the block it can be specified the expected data type of the incoming message. The block converts the incoming message to the specified type and sets the value output signal in case of success or it sets the errId to the resulting error code.

The mode parameter has two available options: Last value and Buffered values. If Last value mode is used the block will always output only the last message received even if multiple messages were received in the last period. If the mode is set to Buffered values than the block buffers the incoming messages and outputs one by one in consecutive ticks of the task.

The defBuffSize parameter can be used to optimize the memory usage of the block. It states the amount of the statically allocated memory in the inner buffer for the incoming messages. If the value is unnecessarily large the memory is being wasted. On the other hand if the value of the parameter is too small it leads to frequent dynamic memory allocations which can be time consuming.

A Subscribe action is performed upon a rising edge (off on) and an Unsubscribe action is performed upon a falling edge (on off) at the RUN input.

The nDRDY output specifies how many messages were received and are available in the inner buffer. If the mode of the block is set to Last value the nDRDY output can only have value 0 or 1.

The RETAIN output flag is set if the received Publish packet had the RETAIN flag set. See the MQTT specification [20] for more details.

Note that subscribing to topics containing wildcards is not supported.

This block does not propagates the signal quality. More information can be found in the 1.4 section.

Input

RUN

Enable execution

Bool

Parameter

topic

MQTT topic

String

QoS

Quality of Service  1

Long (I32)

1 ....

QoS0 (At most once)

2 ....

QoS1 (At least once)

3 ....

QoS2 (Exactly once)

type

Expected type of incoming data  1

Long (I32)

1 ....

string

2 ....

double

3 ....

long

4 ....

bool

5 ....

byte vector/blob

mode

Incoming messages buffering mode  1

Long (I32)

1 ....

Last value

2 ....

Buffered values

defBuffSize

Default buffer size   1 2048

Long (I32)

Output

value

Output signal

Any

nDRDY

Number of received messages   0  10

Long (I32)

RETAIN

Retain last message  on

Bool

errId

Error code

Error

2024 © REX Controls s.r.o., www.rexygen.com