Skip to main content

MQTT IO

Discord

Exposes general purpose inputs and outputs (GPIO), hardware sensors and serial devices to an MQTT server. Ideal for single-board computers such as the Raspberry Pi.

Visit the documentation for more detailed information.

Supported Hardware

Hardware support is provided by specific GPIO, Sensor and Stream modules. It's easy to add support for new hardware and the list is growing fast.

GPIO Modules

  • Beaglebone GPIO (beaglebone)
  • Linux Kernel 4.8+ libgpiod (gpiod)
  • GPIO Zero (gpiozero)
  • MCP23017 IO expander (mcp23017)
  • Orange Pi GPIO (orangepi)
  • PCF8574 IO expander (pcf8574)
  • PCF8575 IO expander (pcf8575)
  • PiFace Digital IO 2 (piface2)
  • Raspberry Pi GPIO (raspberrypi)
  • XL9535/PCA9535/TCA9535 IO expander (xl9535)

Sensors

  • ADS1x15 analog to digital converters (ads1x15)
  • ADXl345 3-axis accelerometer up to ±16g (adxl345)
  • AHT20 temperature and humidity sensor (aht20)
  • AS3935 lightning detector (as3935)
  • BH1750 light level sensor (bh1750)
  • BME280 temperature, humidity and pressure sensor (bme280)
  • BME680 temperature, humidity and pressure sensor (bme680)
  • DHT11/DHT22/AM2302 temperature and humidity sensors (dht22)
  • DS18S20/DS1822/DS18B20/DS1825/DS28EA00/MAX31850K temperature sensors (ds18b)
  • ENS160 digital multi-gas sensor with multiple IAQ data (TVOC, eCO2, AQI) (ens160)
  • FLOWSENSOR generic flow rate sensor like YF-S201, YF-DN50 or others (flowsensor)
  • FREQUENCYCOUNTER Counts pulses from GPIOs and return the frequency in Hz (frequencycounterr)
  • HCSR04 ultrasonic range sensor (connected to the Raspberry Pi on-board GPIO) (hcsr04)
  • INA219 DC current sensor (ina219)
  • LM75 temperature sensor (lm75)
  • MCP3008 analog to digital converter (mcp3008)
  • PMS5003 particulate sensor (pms5003)
  • SHT40/SHT41/SHT45 temperature and humidity sensors (sht4x)
  • TSL2561 light level sensor (tsl2561)
  • VEML7700 light level sensor (veml7700)
  • YF-S201 flow rate sensor (yfs201)

Streams

  • Serial port (serial)
  • PN532 NFC/RFID reader (pn532)

Installation

Requires Python 3.6+

pip3 install mqtt-io

Execution

python3 -m mqtt_io config.yml

Some configuration parameters can be passed as environment variables:

  • MQTT_IO_HOST - Host name or IP address of the MQTT server.
  • MQTT_IO_PORT - Port number to connect to on the MQTT server.
  • MQTT_IO_USER - Username to authenticate with on the MQTT server.
  • MQTT_IO_PASSWORD - Password to authenticate with on the MQTT server.
  • MQTT_IO_PROTOCOL - Version of the MQTT protocol to use.

Environment variables take precedence over configuration files.

Configuration Example

Configuration is written in a YAML file which is passed as an argument to the server on startup.

See the full configuration documentation for details.

The following example will configure the software to do the following:

  • Publish MQTT messages on the home/input/doorbell topic when the doorbell is pushed and released.
  • Subscribe to the MQTT topic home/output/port_light/set and change the output when messages are received on it.
  • Periodically read the value of the LM75 sensor and publish it on the MQTT topic home/sensor/porch_temperature.
  • Publish any data received on the /dev/ttyUSB0 serial port to the MQTT topic home/serial/alarm_system.
  • Subscribe to the MQTT topic home/serial/alarm_system/send and send any data received on that topic to the serial port.
mqtt:
  host: localhost
  topic_prefix: home

# GPIO
gpio_modules:
  # Use the Raspberry Pi built-in GPIO
  - name: rpi
    module: raspberrypi

digital_inputs:
  # Pin 0 is an input connected to a doorbell button
  - name: doorbell
    module: rpi
    pin: 0

digital_outputs:
  # Pin 1 is an output connected to a light
  - name: porch_light
    module: rpi
    pin: 1

# Sensors
sensor_modules:
  # An LM75 sensor attached to the I2C bus
  - name: lm75_sensor
    module: lm75
    i2c_bus_num: 1
    chip_addr: 0x48
  # An INA219 sensor attached to the I2C bus
  - name: ina219_sensor
    module: ina219
    i2c_bus_num: 1
    chip_addr: 0x43


sensor_inputs:
  # lm75 - The configuration of the specific sensor value to use (LM75 only has temperature)
  - name: porch_temperature
    module: lm75_sensor
  # ina219 - The configuration of the specific sensor value to use (4 options for the ina219 sensor)
  - name: power
    type: power
    module: ina219_sensor
  - name: bus_voltage
    type: bus_voltage
    module: ina219_sensor
  - name: current
    type: current
    module: ina219_sensor
  - name: shunt_voltage
    type: shunt_voltage
    module: ina219_sensor

# Streams
stream_modules:
  # A serial port to communicate with the house alarm system
  - name: alarm_system
    module: serial
    device: /dev/ttyUSB0
    baud: 9600

Metadata

Release files for mqtt-io 2.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mqtt-io 2.7.0
File Size Uploaded Provenance
mqtt_io-2.7.0.tar.gz 67.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mqtt-io 2.7.0
File Interpreter ABI Platform
mqtt_io-2.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 171.9 kB

Release files / mqtt_io-2.7.0.tar.gz

Download URL mqtt_io-2.7.0.tar.gz
Size 67.7 kB
Tags Source
SHA-256 checksum
How to use checksums
dca1315530150716c7d1c399c78d59f663bc87e6432ab1d99b44f24b60e333eb
BLAKE2b-256 checksum
How to use checksums
02a01232ab8f2366cca0c8d475f0116328480973732afccc3cb041f1851d3f1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / mqtt_io-2.7.0-py3-none-any.whl

Download URL mqtt_io-2.7.0-py3-none-any.whl
Size 104.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
617827bb8662609d89b0c6c609b0fc7cf64d638eb32dadf248f484ded8877aa1
BLAKE2b-256 checksum
How to use checksums
46fc470cf501cc15620655d408d5ce15a96a268413d1fdae2ec01f7dc8aa5af4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for mqtt-io 2.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

2.7.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page