Skip to main content

Modbus to MQTT gateway — fork of modpoll

Project description

modpoll2mqtt — Modbus to MQTT Gateway

Release Build status License Downloads

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 ref + value 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)
  • 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.

MQTT write by reference

Once connected to the broker, modpoll subscribes to modpoll/+/set. Publish to modpoll/<device>/set:

{
  "ref": "PID_V3V_EC_Consigne_reprise",
  "value": 21.5
}

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 bool with 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 bool with address:bit (0–15), e.g. 40019:15,bool.
  • <endian> must be BE_BE, LE_BE, LE_LE, or BE_LE only.
  • --autoremove disables 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:

License

MIT — see LICENSE.

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

modpoll2mqtt-2.0.0.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

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

modpoll2mqtt-2.0.0-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file modpoll2mqtt-2.0.0.tar.gz.

File metadata

  • Download URL: modpoll2mqtt-2.0.0.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for modpoll2mqtt-2.0.0.tar.gz
Algorithm Hash digest
SHA256 39045e5c78bb652069ad817a4949c7cc4a308b3b24669f404d323f5027734af1
MD5 bbea68b7b1a21f34647eda5855986b47
BLAKE2b-256 ae89657b46785ecb37e521074aac45ddb55c1f6d53aff067b1e8f6855085017f

See more details on using hashes here.

Provenance

The following attestation bundles were made for modpoll2mqtt-2.0.0.tar.gz:

Publisher: on-release-main.yml on yoch/modpoll2mqtt

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

File details

Details for the file modpoll2mqtt-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: modpoll2mqtt-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for modpoll2mqtt-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c22900ed389df1de1a2c9f0e2b956677d4bba740e368b8b006d64d533480fbac
MD5 3883f49ebf79b73774ba09ea9a92a2a9
BLAKE2b-256 822cd2bd0792e6252e55907b27a57563a40776456a774b8f5c6f823e2ebcc90c

See more details on using hashes here.

Provenance

The following attestation bundles were made for modpoll2mqtt-2.0.0-py3-none-any.whl:

Publisher: on-release-main.yml on yoch/modpoll2mqtt

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