Metainformationen zur Seite
LoxBerry::IO::mqtt_connect
$mqttobj = mqtt_connect();
Connects to the MQTT broker defined in MQTT Gateway. Returns a $mqttobj object that can be used with Perl Modul Net::MQTT::Simple
LoxBerry Compatibility
This feature first is available with LoxBerry 2.2.1. Set your LB_MINIMUM version in your plugin.cfg accordingly.
The MQTT connection details are used from the MQTT Gateway settings, therefore the MQTT Gateway plugin needs to be installed.
The $mqttobj connection can be used with the Perl library Net::MQTT::Simple that is included with LoxBerry.
The function returns undef, if the MQTT Gateway isn't reachable.
mqtt_publish, mqtt_retain, mqtt_get
The "fire-and-forget" functions mqtt_publish
, mqtt_retain
and mqtt_get
don't need to have a mqtt_connect() call before. These functions implicitely open an mqtt connection.
Example
use LoxBerry::IO; my $mqtt = mqtt_connect(); $mqtt->subscribe( "my/topic", \&mqttmessage ); while(1) { $mqtt->tick(); } sub mqttmessage { my ($topic, $message) = @_; print "Received: $topic: $message\n"; }