Metainformationen zur Seite
LoxBerry::IO::mqtt_connectiondetails
$hashref = LoxBerry::IO::mqtt_connectiondetails();
Checks if the MQTT Gateway plugin is installed, and returns the configured host and authentication data from the MQTT Gateway plugin.
LoxBerry Compatibility
This feature first is available with LoxBerry 2.0. Set your LB_MINIMUM version in your plugin.cfg accordingly.
Return value
The functions returns a hashref with the following information from the MQTT Gateway plugin for the broker.
The function returns undef
, if the MQTT Gateway plugin is not installed, or the configuration could not be read.
With the broker details, you can establish a full MQTT connection to the configured broker. Use the Net::MQTT::Simple library to connect, publish and subscribe.
With the UDP Inport (udpinport
) you can establish an udp connection to the MQTT Gateway plugin, to easily publish messages. See the udp part of MQTT Gateway - HTTP- und UDP-Interface.
Returning data in a hashref
To access the values, use the syntax e.g. $mqttcred→{brokeraddress}.
Key | Description |
---|---|
brokeraddress | The full address of the broker, e.g. localhost:1883 . |
brokerhost | The hostname part of the broker address, e.g. localhost . |
brokerport | The port part of the broker address, e.g. 1883 . |
websocketport | The websocket port of the broker, eg. 9001 (from LB 2.2.1) |
brokeruser | The username for the broker. The field may be empty if authentication is disabled on the broker. |
brokerpass | The passwort for the broker. The field may be empty, if authentication is disabled or no password is set. |
udpinport | This is the UDP input port of the MQTT Gateway on the local installation. See MQTT Gateway - HTTP- und UDP-Interface |
Usage
use LoxBerry::IO; my $mqttcred = LoxBerry::IO::mqtt_connectiondetails(); print $mqttcred->{brokerhost}.':'.$mqttcred->{brokerport};
See also
- LoxBerry::IO::mqtt_connect - Establishes a ready connection to the MQTT Broker configured by the user in MQTT Gateway. It wraps the connection process using the mqtt_connectiondetails settings.
- LoxBerry::IO::mqtt_publish/mqtt_retain/mqtt_set - "Shoot-and-forget" functions to directly publish messages, or fetch retained messages from the broker. Connection processing is done implicitely by the functions.