Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Use mqtt_connectiondetails to check/aquire the broker settings.
  2. Connect to the broker by the phpMQTT.php library.

Use-Cases for

...

Read broker settings and credentials from MQTT Gateway plugin

https://gist.github.com/christianTF/fe4d233a2a68aa63b11c9c76b60697b2

...

other languages (Python, Node.js, etc.)

...

  • The MQTT Gateway plugin needs to be installed on the local LoxBerry.
  • The user can configure an external broker in MQTT Gateway (hostname, port, username, password).
  • The example function aquires these settings from the MQTT Gateway. 
  • Your code connects to this broker (independent if local or not) without any configuration and parameters neither in your user interface nor your config files.   

Use-Cases for other languages (Python, Node.js, etc.)

Read broker settings and credentials

...

Starting with MQTT Gateway 2.0 (Release) the broker settings are provided directly in LoxBerry's main configuration file, general.json. See the Mqtt section in general.json.

Read broker settings and credentials

To get LoxBerry's home, read the global system environment variable $LBHOME - on original LoxBerry, this is /opt/loxberry

  1. Open and json-parse $LBHOME/config/system/general.json
  2. Connection settings and credentials are provided in
    • Mqtt.Brokeruser
    • Mqtt.Brokerpass
    • Mqtt.Brokerhost
    • Mqtt.Brokerport
  3. Some further rules:
    1. If the base object "Mqtt" is not defined, MQTT Gateway is not installed (or version is too old)
    2. If Brokeruser is empty, the broker has anonymous access enabled.
    3. If Brokerpass is empty, the broker has user login without password enabled.
    4. Brokerhost and Brokerport are always set - you don't need to fallback to localhost or a default port

Brokerport is the unencrypted MQTT TCP port without TLS.

Get UDP in-port of MQTT Gateway plugin to publish messages via the MQTT Gateway

...

To get LoxBerry's home, read the global system environment variable $LBHOME - on original LoxBerry, this is /opt/loxberry

  1. Open and json-parse $LBHOME/config/system/general.json
  2. The MQTT Gateway UDP port is 
    • Mqtt.Udpinport
  3. Create a UDP outbound socket to localhost:<udpinport><Udpinport>
  4. With the UDP interface described here (MQTT Gateway - HTTP- und UDP-Interface), you can publish messages to the broker in a very easy way.

...