MQTT

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.

Extension Configs

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.

OptionTypeRequiredDescription
key[String]YesUnique slug id for the connection. This is referenced by the interfaces.
host[String]NoHost address of the mqtt broker. Default: localhost
port[Integer]NoPort of the mqtt broker. Default: 1883

Config

Here is a config of a connection config.

"mqtt": [{
    "key": "localhost_mqtt",
    "host": "localhost",
    "port": 1883
}]

Sensor Interface

Provides a sensor to get data by listening for an event.

OptionTypeRequiredDescription
key[String]YesUnique slug id for the component
connection[String]YesThe key from the mqtt connection config.
topic[String]Notopic for the sensor to listen on. Default: sensor/{key}
expires[Integer]NoTime in seconds that state should be considered invalid. 0 = disabled. Default: 0
name[String]NoFriendly display name of component. Useful for UI.
classifier[String]NoChoose a specific sensor classifier to change formatting on frontend. Default: general

Config

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"
}]

Publish Data Manually

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"