Documentation

MQTT Extension

The MQTT extension allows you to connect to a local or remote MQTT broker and gather data from events.

Overview

The mqtt extension allows you to connect to an MQTT broker and gather data from events. You may connect to a local or remote broker.

Note

As of MudPi v0.11.0, the MQTT extension uses paho-mqtt 2.x. No configuration changes are needed — MudPi handles the migration internally. If you have custom extensions that import paho.mqtt.client directly, review the paho-mqtt 2.x migration guide.

Extension Configuration

This extension has configurations required on the extension level to set up 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.

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

Connection Config Example

mudpi.config.json
{
  "mqtt": [
    {
      "key": "localhost_mqtt",
      "host": "localhost",
      "port": 1883
    }
  ]
}

Sensor Interface

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

Config Example

mudpi.config.json
{
  "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 use the mosquitto_pub command to send data manually:

Terminal
mosquitto_pub -h 127.0.0.1 -t mudpi/example/topic -m "10"