Metainformationen zur Seite
LoxBerry::IO::mqtt_publish/mqtt_retain/mqtt_set
$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)
LoxBerry Compatibility
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.
Publishes the $value
to the specified $topic
.
With mqtt_publish
and mqtt_retain
, the messages are published without and with retain flag.
With mqtt_set
, the retain flag is the third parameter of the function call:
- If the
$retain
parameter is omitted or undef, a publish is used. - If the
$retain
parameter is 1 (not undef), the message is published with retain flag set.
Return
The functions return the $topic as string, if the publish was successful.
The functions return undef on any errors.
mqtt_connect
This functions do not require to first call mqtt_connect, as the connection to the mqtt broker is implicitely opened.
Example
use LoxBerry::IO; mqtt_publish( "hello/you", "You are you" ); mqtt_retain( "hello/me", "I am I" ); mqtt_set( "hello/we", "We are we", 1 );