Decode registers into engineering values before publishing, and publish a quality flag when a device stops answering, never a stale number.
Why Bridge Modbus to MQTT
Modbus is polled: a client asks a device for registers and gets numbers with no names. MQTT is publish and subscribe: a value goes to a named topic and any number of consumers can use it. A bridge polls the registers and publishes the decoded values, so analytics, dashboards and other systems share one clean feed.
Polling and Publishing
Group contiguous registers into single requests and set a poll interval per device, because a slow RS-485 trunk cannot be polled as fast as an Ethernet meter. Publish on a fixed interval, or only when a value changes by more than a deadband, so the broker is not flooded with identical readings.
Decode Before You Publish
Apply the scale factor, word order and unit from the register map inside the bridge, so the payload holds an engineering value such as 230.1 volts and not the raw register 2301. Consumers should never need to know a device's register layout.
Topic and Payload Design
Use a path from broad to specific, for example plant/line-1/meter-3/active-power. Send a small JSON payload with the value, the unit and a timestamp. Keep one measurement per topic so wildcard subscriptions stay useful.
QoS, Retained Values and Failure
QoS 1 suits most telemetry. A retained message lets a new subscriber see the last value at once, but include the timestamp so a stale value is recognisable. Use an MQTT Last Will to signal that the bridge has gone offline unexpectedly. A Will is not sent after a clean disconnect, so also publish a retained online status on connect and replace it with offline on a clean shutdown. Mark readings as bad quality when a device stops answering.
Verify with One Known Value
Before rolling out, compare one published value with the device display or a handheld meter. A single correct comparison confirms the address, scale and word order together.
Common Questions
What is a Modbus to MQTT gateway?
It is software or a device that polls Modbus registers, converts the raw numbers into engineering values and publishes them to MQTT topics. Standard Modbus devices only answer requests and cannot send data unprompted, so the gateway acts as the client on the Modbus side and as an MQTT client on the broker side.
Can MQTT replace Modbus on a site?
Not directly. Modbus is how many meters, drives and PLCs expose data, and they do not speak MQTT natively. MQTT is the messaging layer used to share that data between systems. Most sites keep Modbus at the device and add MQTT upstream through a gateway.
