$senttopic = mqtt_publish( $topic, $value );
$senttopic = mqtt_retain( $topic, $value );
$senttopic = mqtt_set( $topic, $value, $retain );
Publishes a value to a MQTT topic with or without retain flag. The MQTT connection is implicitely opened to call the publish. (MQTT Gateway plugin required)
This functions first are available with LoxBerry 2.2.1. Set your LB_MINIMUM version in your plugin.cfg accordingly.
The MQTT connection is implicitely opened to the MQTT broker defined in MQTT Gateway plugin, therefore the MQTT Gateway plugin needs to be installed.
$value to the specified
mqtt_retain, the messages are published without and with retain flag.
mqtt_set, the retain flag is the third parameter of the function call:
- If the
$retain parameter is omitted or false, a publish is used.
- If the
$retain parameter is true, the message is published with retain flag set.
The functions return the $topic as string, if the publish was successful.
The functions return null on any errors.
This functions do not require to first call mqtt_connect, as the connection to the mqtt broker is implicitely opened.
mqtt_set( "hello/you", "publishing content with retain", true );
mqtt_set( "hello/you", "publishing content without retain", false );
mqtt_publish ("hello/you", "publishing content" );
mqtt_retain ("hello/you", "publishing with retain flag" );