The mqtt
extension allows you to connect to a mqtt broker and gather data from events. You may connect to a local or remote broker.
This extension has some configurations required on the extension level to setup the connection. First you should add configs for your mqtt
connection and supply a key
. Then any interfaces will reference this key to use the connection. This reduces unnecessary connections by centralizing the connection logic on the extension level and letting the interfaces focus on just using the already established connection.
Option | Type | Required | Description |
key | [String] | Yes | Unique slug id for the connection. This is referenced by the interfaces. |
host | [String] | No | Host address of the mqtt broker. Default: localhost |
port | [Integer] | No | Port of the mqtt broker. Default: 1883 |
Here is a config of a connection config.
"mqtt": [{
"key": "localhost_mqtt",
"host": "localhost",
"port": 1883
}]
Provides a sensor to get data by listening for an event.
Option | Type | Required | Description |
key | [String] | Yes | Unique slug id for the component |
connection | [String] | Yes | The key from the mqtt connection config. |
topic | [String] | No | topic for the sensor to listen on. Default: sensor/{key} |
expires | [Integer] | No | Time in seconds that state should be considered invalid. 0 = disabled. Default: 0 |
name | [String] | No | Friendly display name of component. Useful for UI. |
classifier | [String] | No | Choose a specific sensor classifier to change formatting on frontend. Default: general |
Here is a config of a complete mqtt sensor.
"sensor": [{
"key": "mqtt_sensor",
"interface": "mqtt",
"connection": "localhost_mqtt",
"topic": "mudpi/example/topic",
"expires": 3600,
"classifier": "general"
}]
Once you have everything configured you can then use the mosquitto_pub
command to send data manually.
mosquitto_pub -h 127.0.0.1 -t mudpi/example/topic -m "10"