MqttPublish – Publish MQTT message

Block SymbolLicensing group: MQTT
PIC

Function Description

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

The MqttPublish block publishes messages to an MQTT broker through the connection established by the MQTTDrv driver.

The first parameter is the topic the block will publish the messages to. MQTT 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 [11] for more details.

If the RETAIN parameter is set a RETAIN flag will be set on the outgoing PUBLISH Control Packet. See the MQTT specification [11] for more details.

The defBuffSize parameter can be used to optimize the memory usage of the block. It states the amount of the statically allocated memory for the inner buffer for the outgoing 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.

The message to be published is constructed from the value input signal. The value input signal is expected to be a string. If it is not a string it will be converted automatically. To request a message to be published in the current period set the RUN flag to on. The BUSY flag is on if the block has a pending request and waits for a response from a broker. When the response is received in the current cycle the DONE flag is set to on.

Inputs

value

Input signal

String

RUN

Enable execution

Bool

Parameters

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)

RETAIN

Retain last message  on

Bool

defBuffSize

Default buffer size   1 2048

Long (I32)

Outputs

BUSY

Busy flag

Bool

DONE

Indicator of finished transaction

Bool

errId

Error code

Error

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