MQTT Configuration
Last updated
Last updated
GreenLightning has built-in MQTT support for Internet-of-Things projects or other types of applications. See MQTT Client for more information on how to create a MQTT client with GreenLightning. Learn how to create a MQTT Client .
To enable MQTT support and to create a custom MQTT configuration, use the following code:
You can add more configurations by appending them to the last configuration:
Enables MQTT usage. maxInFlight
is an optional argument that lets you specify the maximum number of supported in-flight messages.
If no data is sent or received over an open connection for a certain time period then the client will generate a PINGREQ and expect to receive a PINGRESP from the broker. This specifies that interval in seconds.
This message exchange confirms that the connection is open and working.
If your broker requires username and password authentication, set it here. You can optionally pass in TLS certificates if broker is using TLS with authentication.
Sets the default quality-of-service for message transmission.
Sets the default quality-of-service for subscriptions.
Lets broker know if transmissions should be retained or not by default.
The topic for broadcasting if connection is established or not.
Lets broker know if a clean session is required on connection. See for more information about this flag.
When the client disconnects, this will be the last message sent before disconnect is finished. topic
is the topic the message should be broadcast to, retain
determines if a client that tries to subscribe to the last will topic will receive the last will message or not, qos
specifies level for MQTT, and payload
is the payload sent in the last will message.
Enable TLS for MQTT connection. Specify custom certificates if required (otherwise uses default, see ).