MqttSubscribe – Subscribe to MQTT topic
Block SymbolLicensing group: MQTT
Function Description
This function block depends on the MQTT driver. Please read the MQTTDrv manual [22] 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 [23] 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 (offon) and an Unsubscribe action is performed upon a falling edge (onoff) 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 [23] 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) |
|
|
|
type | Expected type of incoming data 1 | Long (I32) |
|
|
|
mode | Incoming messages buffering mode 1 | Long (I32) |
|
|
|
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 |
[Previous] [Back to top] [Up]
2024 © REX Controls s.r.o., www.rexygen.com