Modbus to MQTT gateway — fork of modpoll
Project description
modpoll2mqtt — Modbus to MQTT Gateway
Documentation: yoch.github.io/modpoll2mqtt
modpoll2mqtt is a command-line Modbus-to-MQTT gateway. It polls Modbus devices (RTU, TCP, UDP) using CSV configuration files, publishes values to an MQTT broker, and accepts write commands by CSV reference name.
Install the PyPI package as modpoll2mqtt; the executable command remains modpoll.
Fork of modpoll, with semantic MQTT writes by CSV reference name and CTA (air handling unit) examples.
Features
- Modbus RTU, TCP, and UDP (CSV configuration files)
- Local display of polled data (debug mode)
- MQTT publishing of references (configurable topics)
- Optional MQTT retain on data publishes (
--mqtt-retain) - MQTT writes by CSV reference name (
modpoll/<device>/set) - Local CSV export of polled data
- Bit-level access on registers and coils
Installation
Python 3.10+ required.
pip install modpoll2mqtt
Optional serial support (pyserial):
pip install 'modpoll2mqtt[serial]'
Upgrade:
pip install -U modpoll2mqtt
On Windows, pipx is recommended:
pipx install modpoll2mqtt
Quickstart
Single poll of a Modbus TCP device (replace the IP address with yours):
modpoll --once \
--tcp 192.168.1.10 \
--config examples/modsim.csv
Publish to an MQTT broker:
modpoll \
--tcp 192.168.1.10 \
--mqtt-host broker.emqx.io \
--config examples/modsim.csv
Data is published to modpoll/<device_name>/data by default.
Add --mqtt-retain so the broker keeps the last data message per topic for new subscribers. Diagnostics topics are never retained. If a device goes offline, retained values may still appear live until the next successful publish.
MQTT write by reference
Once connected to the broker, modpoll subscribes to modpoll/+/set. Publish to modpoll/<device>/set:
{
"PID_V3V_EC_Consigne_reprise": 21.5,
"BP_MA_CTA": true
}
Unknown reference names in the payload are skipped with a warning.
Example with examples/CTA/cta_conf_restaurant.csv: an int16 reference with scale 0.1 accepts 21.5 as input; the raw register value 215 is written.
Migration from modpoll 1.6.x: the low-level format (object_type, address, value) is no longer supported.
Configuration pitfalls
- On coil or discrete_input pollers, use
boolwith the absolute Modbus coil address for a single boolean. bool8/bool16: legacy grouped reads (group index, not a direct coil address).- On holding_register or input_register, use
boolwithaddress:bit(0–15), e.g.40019:15,bool. <endian>must beBE_BE,LE_BE,LE_LE, orBE_LEonly.--autoremovedisables a poller after 3 consecutive Modbus failures.
Examples
# Modbus TCP
modpoll --tcp 192.168.1.10 --config examples/modsim.csv
# Modbus serial
modpoll --serial /dev/ttyUSB0 --serial-baud 9600 --config contrib/eniwise/scpms6.csv
# MQTT + CSV export
modpoll --tcp 192.168.1.10 --mqtt-host localhost --export data.csv --config examples/modsim.csv
# Multiple config files
modpoll --tcp 192.168.1.10 --config examples/modsim.csv examples/modsim2.csv
# CTA (building automation example)
modpoll --tcp 192.168.1.20 --mqtt-host localhost --config examples/CTA/cta_conf_restaurant.csv
See examples/ and contrib/ for more device configurations.
Credits
This project builds on:
- modpoll — Ying Shaodong (MIT)
- modbus2mqtt — Oliver Wagner (MIT)
- spicierModbus2mqtt — Max Brueggemann (MIT)
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file modpoll2mqtt-2.1.1.tar.gz.
File metadata
- Download URL: modpoll2mqtt-2.1.1.tar.gz
- Upload date:
- Size: 23.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
887a84216ccd0c209174918ec794242845b3241ab9e16a9afc4f08e8b9779276
|
|
| MD5 |
8f8dc6e68780252aed32c3141e572b51
|
|
| BLAKE2b-256 |
c638f6db6e8116457b73e7eec2d48a0444e9f8763373ed542c50c17e4d55026b
|
Provenance
The following attestation bundles were made for modpoll2mqtt-2.1.1.tar.gz:
Publisher:
on-release-main.yml on yoch/modpoll2mqtt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modpoll2mqtt-2.1.1.tar.gz -
Subject digest:
887a84216ccd0c209174918ec794242845b3241ab9e16a9afc4f08e8b9779276 - Sigstore transparency entry: 1790687780
- Sigstore integration time:
-
Permalink:
yoch/modpoll2mqtt@4a095afa03f8284f56e8b43866356ef70d1ba239 -
Branch / Tag:
refs/tags/v2.1.1 - Owner: https://github.com/yoch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-main.yml@4a095afa03f8284f56e8b43866356ef70d1ba239 -
Trigger Event:
push
-
Statement type:
File details
Details for the file modpoll2mqtt-2.1.1-py3-none-any.whl.
File metadata
- Download URL: modpoll2mqtt-2.1.1-py3-none-any.whl
- Upload date:
- Size: 24.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a85458fd0c77c68c3e2dc64783c18a9ea64b778bff3013dff4cbd219845026aa
|
|
| MD5 |
9f7c4b591cfab57caf4ba7278c1df2c6
|
|
| BLAKE2b-256 |
6b15fbe92a205179d00c3616119bc6a7c658cb77a8bd3f790d91eb2680ba786e
|
Provenance
The following attestation bundles were made for modpoll2mqtt-2.1.1-py3-none-any.whl:
Publisher:
on-release-main.yml on yoch/modpoll2mqtt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modpoll2mqtt-2.1.1-py3-none-any.whl -
Subject digest:
a85458fd0c77c68c3e2dc64783c18a9ea64b778bff3013dff4cbd219845026aa - Sigstore transparency entry: 1790687829
- Sigstore integration time:
-
Permalink:
yoch/modpoll2mqtt@4a095afa03f8284f56e8b43866356ef70d1ba239 -
Branch / Tag:
refs/tags/v2.1.1 - Owner: https://github.com/yoch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-main.yml@4a095afa03f8284f56e8b43866356ef70d1ba239 -
Trigger Event:
push
-
Statement type: