Skip to main content

Shares all the serial ports on a system to an mqtt broker

Project description

UART2MQTT

A minimal Python bridge that connects USB UART devices to MQTT topics. It automatically discovers USB serial devices, filters them using a VID:PID allow list, and creates bidirectional communication between each serial port and its associated MQTT topic.

Features

  • Automatically detects serial devices via /dev/serial/by-path
  • Filters devices using VID/PID from /sys/class/tty/...
  • Bidirectional communication between UART and MQTT
  • Dynamic topic generation: <topic_base>/<port>/device_serial_output
  • Configurable via a TOML file at /etc/uart2mqtt.toml

Configuration

Create /etc/uart2mqtt.toml:

[mqtt]
host = "mqtt-broker.local"
port = 1883
topic_base = "testbench"


# USB match sections are optional. If specified, it only matches with
# listed vid:pids. Can list [[usb_match]] multiple times, and can use "*" as 
# wilcards.
[[usb_match]]
vid = "1a86"
pid = "7523"

# If no usb_match is specified, all devices are matched similar to this:
[[usb_match]]
vid = "*"
pid = "*"

Usage

Run the bridge:

uart2mqtt

See the example "uart2mqtt.service" example file as well. Update it to include the user this will run as, then:

cp /uart2mqtt.service /etc/systemd/system/uart2mqtt.service
systemctl --now enable uart2mqtt.service

Requirements

  • Python 3.11+
  • pyserial
  • paho-mqtt

Development Setup:

After cloning, install the git pre-commit hooks.

# Run once:
pre-commit install

# To run by hand before a commit
pre-commit run --all-files

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uart2mqtt-0.1.2.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uart2mqtt-0.1.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file uart2mqtt-0.1.2.tar.gz.

File metadata

  • Download URL: uart2mqtt-0.1.2.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for uart2mqtt-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6b2215863e35b68907519799b9a9a762caf2028688b40e74a6358ce67dbffdd3
MD5 0890f2d6defb2cc46fa32b27a87d5509
BLAKE2b-256 f18569bce8bd857e9acd720c1dee84f6c32497c57c4bdaa9a4d153fb323cdab6

See more details on using hashes here.

Provenance

The following attestation bundles were made for uart2mqtt-0.1.2.tar.gz:

Publisher: release.yml on embeddedTS/uart2mqtt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file uart2mqtt-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: uart2mqtt-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for uart2mqtt-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 97ab3e2fc6a66c279a465b6026b649bef74371040349320a61b777d32fb50514
MD5 6794f822e12d34bacc77adcaa97d2d41
BLAKE2b-256 7c13fa624b97f54e366453f97170d64f8d0a04acab0de1b662a30c1a00166477

See more details on using hashes here.

Provenance

The following attestation bundles were made for uart2mqtt-0.1.2-py3-none-any.whl:

Publisher: release.yml on embeddedTS/uart2mqtt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page