Skip to content
Nuvologic Electronics, home Discuss your requirement

8 min read

Modbus RTU to MQTT: how machine data reaches your dashboard

Most machines, meters and drives in a plant already hold the numbers a manager wants: run status, cycle counts, fault codes, energy. Usually they sit in Modbus registers, read over an RS-485 cable. The job is to read them reliably and deliver them to the dashboard, database or SCADA system where people actually look. Today, the usual route for that last step is MQTT.

This guide follows one value from a Modbus register to a dashboard tile. It covers the decisions along the way and the mistakes that cost the most commissioning time.

MACHINE SIDE GATEWAY NETWORK SIDE PLC SLAVE ID 1 ENERGY METER SLAVE ID 2 VFD SLAVE ID 3 120 Ω 120 Ω RS-485 MODBUS RTU 9600 8E1 Gateway MODBUS MASTER POLL · SCALE TIMESTAMP STORE AND FORWARD MQTT CLIENT MQTT · TLS PORT 8883 Broker TOPICS · QOS DASHBOARD DATABASE SCADA · ERP REQUEST AND RESPONSE ON THE BUS · PUBLISH AND SUBSCRIBE ON THE NETWORK
One RS-485 bus, one gateway, one broker. The gateway is the Modbus master on the machine side and an MQTT client on the network side.

Two protocols, two jobs

Modbus RTU is a request and response protocol on a serial line, almost always RS-485 in a plant. One master asks; each slave, with an address from 1 to 247, answers only when asked. Frames are binary and checked with a CRC. Modbus has no security, no timestamps and no way for a device to say “this value just changed”. It is simple and almost universal, which is why it is still everywhere.

MQTT is a publish and subscribe protocol over TCP/IP. A device publishes messages on named topics to a broker; dashboards, databases and other systems subscribe to the topics they need. It was designed for unreliable networks. Keep-alives detect a lost connection. Quality-of-service levels control delivery. A retained message gives a new subscriber the last value straight away. A “last will” message tells everyone when a device drops off.

The gateway translates between the two. On the machine side it acts as the Modbus master and polls each device. On the network side it is an MQTT client that publishes what it has read.

Step 1: list the values, not the machines

Start from the decisions the data should support, then work back to the values:

  • Output per shift: the cycle or part counter in each machine’s PLC.
  • Downtime and its causes: run and stop status, plus fault or alarm codes.
  • Energy per shift or per part: active energy (kWh) from the energy meters.
  • Process quality: the temperatures, pressures or speeds that matter for that process.

For each value, note its unit and how often it is really needed. A status bit may be worth reading every second; an energy total every minute is plenty. Our machine data checklist (Excel) sets this out as a table.

Step 2: get the register map

The device manual lists its registers. The function code says what kind of data is being read or written:

Function codeWhat it doesTypical use
01 Read coilsReads on/off outputsOutput states in a PLC
02 Read discrete inputsReads on/off inputsInput states, read-only
03 Read holding registersReads 16-bit values that can also be writtenMost PLC data, many meters and drives
04 Read input registersReads 16-bit read-only valuesMeasured values in many meters and drives
05 and 06Writes one coil or one registerCommands and set points
15 and 16Writes several coils or registersRecipes and blocks of settings

For every value on your list, record four things:

  1. Address, and how the manual counts. Some manuals give the protocol address, which starts at 0. Others use the “40001” convention, where 40001 means holding register 0.
  2. Data type. 16-bit signed or unsigned, 32-bit integer, or 32-bit floating point.
  3. Word order. A 32-bit value spans two registers, and devices disagree on which one holds the high half.
  4. Scaling. A raw 2345 may mean 234.5 V, so note the multiplier and the unit.

Check one value before you trust the rest. Most wrong readings come from two mistakes. An address one place off returns the neighbouring value, which can look plausible. A 32-bit value read in the wrong word order usually gives an absurd number. Compare one reading with the device’s own display before mapping the rest.

Step 3: check the RS-485 line

Most “the gateway does not work” calls turn out to be wiring or settings on the serial line:

  • One set of settings per bus. Every device on a bus must use the same baud rate and framing. The specification’s default is even parity with one stop bit, or two stop bits without parity, although many devices also offer no parity with one stop bit. Each device also needs its own address.
  • A daisy chain, not a star. Run one twisted pair from device to device. Long branches off the main line cause reflections.
  • Termination at both ends only. Fit a 120 Ω resistor at each end of the cable, nowhere else. Bias the line once, so it rests in a known state between frames.
  • A reference conductor. RS-485 is differential, but the devices still need a common reference. Where devices sit on different earths or in different panels, an isolated port avoids ground-loop trouble.
  • Know the limits. A standard segment carries up to 32 unit loads, more with fractional-load transceivers, and reaches about 1,200 m at the lower baud rates.

Step 4: work out the polling budget

Modbus RTU is slow by network standards, and this is the step most projects skip. At 9600 baud with even parity, each byte takes about 1.15 ms. Reading ten registers takes an 8-byte request and a 25-byte reply. Add the silent gap the protocol requires between frames and the device’s own reply time, and one read usually takes 50 to 100 ms.

Twenty energy meters with three reads each is sixty reads, so one full round of the bus takes roughly three to six seconds. Polling every ten seconds is comfortable; polling everything every second is not possible. To get more out of a bus:

  • Read blocks, not single values. Read neighbouring registers in one request; a single read can return up to 125 registers.
  • Poll by need. Read status often and energy totals rarely.
  • Raise the baud rate to 19200 or 38400 if every device on the bus supports it.
  • Split long buses across two serial ports.

Step 5: design the MQTT side

Topics. A predictable topic structure saves work in every system that subscribes. A common pattern is site, area, machine and value:

pune-plant/press-shop/press-02/cycle-count

Alternatively, publish one topic per machine with a JSON payload that carries several values and a timestamp:

{"ts": "2026-10-30T10:15:00+05:30", "run": true, "cycle_count": 18234, "fault": 0}

If your SCADA system supports Sparkplug B, an open specification for industrial MQTT, consider it. It defines the topic names, the payload encoding and how devices announce that they are online or offline.

Quality of service. QoS 0 delivers at most once, QoS 1 at least once and QoS 2 exactly once. QoS 1 is the usual choice for machine data; the receiving side should simply ignore a duplicate.

When to publish. Publish status changes as they happen. Publish analog values when they move by more than a set deadband, plus a regular heartbeat so silence is never mistaken for “nothing changed”. Retain the last value, so a dashboard that opens shows the current state, and set a last-will message that marks the gateway offline.

Step 6: plan for the network going down

Plant networks and mobile links drop, so plan for it from the start:

  • Timestamp at the gateway, when the value is read, not at the server when it arrives.
  • Store and forward. Buffer readings while the link is down, then send them in order with their original timestamps. Size the buffer: 50 values every ten seconds is 432,000 readings a day.
  • Prefer counters to rates. A cycle counter or a kWh total survives a gap, because the difference between two readings still gives the right answer.

Step 7: security basics

  • Keep Modbus on the machine network. Modbus has no authentication or encryption, so never expose a Modbus TCP port (502) to the internet.
  • Connect outwards only. The gateway connects out to the broker, so no inbound port has to be opened in the plant firewall.
  • Encrypt and identify. Use MQTT over TLS (port 8883). Give each gateway its own credentials or certificate, and set broker permissions so each gateway can publish only to its own topics.
  • Read-only by default. Writing registers from the cloud should be a deliberate decision, with limits, not a side effect of the set-up.

A checklist before you start

  • The values you need, with units and how often each is needed
  • Make and model of every device, and the manual with its register map
  • Serial settings and slave address of each device, and a sketch of the bus wiring
  • Where the data must go: dashboard, database, SCADA, ERP or a cloud platform
  • How the site connects to the outside: plant LAN, Wi-Fi or mobile data, and the IT rules for outbound connections

Nuvolink, our IoT gateway, does exactly this job. It reads the values your machines, meters and instruments already hold, over Modbus RTU, Modbus ASCII or Modbus TCP, and delivers them over MQTT, HTTP or HTTPS to the system you use, without replacing the equipment. Every installation starts with a fit check: an engineer reviews your equipment, data points and destination before anything is installed.

To start, map your data path on the Nuvolink page, or send the checklist above with your enquiry. For a connected product of your own rather than existing machines, see IoT integration.

All articles