int mqtt_publish( MQTT handle, const char* topic, const char* payload, int length, enum MQTT_QOS qos, enum MQTT_RETAIN_FLAG retainFlag);
|Example||MQTT Vuser Functions|
|handle||The MQTT client handle returned by mqtt_create.|
|topic||The destination topic as a null-terminated string, for example
|payload||The message payload as a pointer to a binary buffer or a null-terminated string.|
|length||The message payload length in bytes. Pass MQTT_AUTO for NULL-terminated strings.|
|qos||The required quality of service. An element of the MQTT_QOS enum. One of:
The message retention flag. An element of the MQTT_RETAIN_FLAG enum. One of:
mqtt_publish publishes a message to the specified topic.
If the connection is lost during an mqtt_publish operation where QoS = 0, the client will not try to publish again after reconnecting, and a warning will be displayed in the script's output.
You can limit the number of published messages in the incoming message queue (Inbox) by setting the MQTT runtime setting, Maximium number of pending messages in the Inbox. (Default: 1000 messages.) If the Inbox contains more than the defined number of messages, the script will end with an error.
If invalid arguments are passed, the Vuser aborts, even if Continue on error is set.
MQTT_SUCCESS or MQTT_FAIL
Standard parameterization is available for this function.
Exception: payload cannot be parametrized.
/* Publish message "20 degrees" to the topic "sensors/temperature/room1" and store the message with default QoS.
The length is a null-terminated string that is calculated automatically because MQTT_AUTO is passed.
mqtt_publish(client, "sensors/temperature/room1", "20 degrees", MQTT_AUTO, MQTT_DEFAULT, MQTT_RETAIN);