DEV Community

Cover image for Modbus to MQTT with Node-RED: Why the Message Model Matters
Jerry H.
Jerry H.

Posted on

Modbus to MQTT with Node-RED: Why the Message Model Matters

A Modbus-to-MQTT workflow can look simple from the outside.

Read a register. Publish a message. Show the value in a dashboard.

In real industrial IoT projects, that middle step is where many problems appear. A Modbus value is not automatically meaningful to an MQTT broker, cloud platform, or dashboard. The edge flow has to turn field-side data into a message that another system can actually understand.

That is where Node-RED can be useful. It can act as the flow layer between Modbus collection and MQTT publishing, helping teams map raw values, add context, filter unnecessary updates, and publish structured payloads.

A Robustel edge gateway EG5120 can be used as a practical reference for this kind of edge data workflow, especially when the project needs industrial interfaces, Docker-based applications, Modbus TCP/RTU data paths, MQTT-to-cloud forwarding, cellular backhaul, and remote gateway management.

The key point is direct: Modbus-to-MQTT is not just protocol conversion. It is field-data interpretation.

The mistake: treating Modbus and MQTT as the same kind of problem

Modbus and MQTT often appear in the same industrial IoT architecture, but they solve different problems.

Modbus is usually closer to the field equipment. PLCs, meters, drives, controllers, and industrial devices may expose values through Modbus RTU or Modbus TCP. These values are often represented as registers, coils, addresses, or device-specific fields.

MQTT is usually closer to the application side. It helps gateways, brokers, platforms, and cloud systems exchange structured messages through topics and payloads.

So the practical split is this:

Modbus reads field values.
MQTT publishes usable messages.
Enter fullscreen mode Exit fullscreen mode

The hard work sits between those two lines. A Modbus register may carry a valid value, but the receiving system still needs to know what that value means.

A raw register does not explain itself

A value like 40001 = 1 does not tell the full story.

Depending on the device and register map, it may mean machine running, alarm active, relay closed, manual mode, inverter enabled, or something else entirely. Even a numeric value can be misleading without scaling and units. A raw value of 350 might mean 35.0°C, 350 V, 350 A, or a coded status.

This is why a Modbus-to-MQTT workflow should start with the data model, not the Node-RED canvas.

Before building the flow, the team should know the register address, data type, unit, scaling rule, polling interval, asset ID, and destination format. A small first version with 10–30 selected values is usually easier to test than a large flow that tries to collect every available register.

The conclusion is simple: if the tag list is unclear, the flow will only move confusion faster.

What a useful MQTT payload should carry

An MQTT topic and payload should help the receiving system understand where the value came from and how it should be used.

A weak topic might look like this:

data
Enter fullscreen mode Exit fullscreen mode

A more useful topic carries asset context:

factory_a/line_02/compressor_04/energy/power_kw
Enter fullscreen mode Exit fullscreen mode

The payload should do the same. It should explain the value, not only transmit it.

{
  "asset_id": "compressor_04",
  "tag": "power",
  "value": 12.7,
  "unit": "kW",
  "timestamp": "2026-07-15T08:00:00Z",
  "quality": "good",
  "source": "modbus_register_40021"
}
Enter fullscreen mode Exit fullscreen mode

This kind of message is easier to validate, route, store, and display. It also makes the system easier to maintain when another dashboard, database, or cloud application needs to consume the same data later.

For broader protocol background, Robustel’s overview of IoT gateway protocols from Modbus and OPC UA to MQTT is a useful reference.

Where Node-RED helps

Node-RED is useful because it lets teams build the middle layer visually. A flow can read selected Modbus values, normalize data types, add context, filter repeated values, handle basic routing, and publish MQTT messages.

That makes it a good fit for early industrial IoT workflows where the team needs to prove that field-side data can support monitoring, dashboards, reporting, or cloud integration.

But Node-RED does not automatically know what a register means. It still depends on the device manual, register map, installed nodes, runtime setup, credentials, network path, and security policy.

It is also not the control layer. Node-RED can support data movement and message preparation, but PLCs and dedicated controllers should remain responsible for deterministic control, interlocks, timing-critical sequences, and safety-related functions.

Why the gateway host layer matters

A Node-RED Modbus-to-MQTT workflow needs a stable place to run.

That host layer matters more than people sometimes expect. The gateway needs the right field interfaces, network connectivity, runtime environment, security controls, and management process. A flow that works during a test may still fail in production if the device cannot be maintained, secured, restarted, or monitored properly.

This is where Robustel edge gateway EG5120 can fit as an industrial edge gateway reference. It can support selected workflows involving Modbus TCP/RTU, serial-side access, Docker-based edge applications, MQTT-to-cloud data paths, cellular or Ethernet backhaul, VPN-based secure communication, and RCMS-based remote gateway management.

That does not mean every Node-RED node, industrial protocol, or field device is supported automatically. Final suitability still depends on firmware, installed packages, Node-RED nodes, data volume, interface wiring, security policy, and project validation.

Test before publishing upstream

A Modbus-to-MQTT flow should not be treated as production-ready just because the broker received a message once.

A better validation plan should test normal reads, Modbus timeout, wrong register values, gateway reboot, MQTT broker outage, WAN recovery, and stale-data handling. The important question is whether the flow fails visibly or silently publishes misleading data.

For example, if a field device stops responding, the payload should not keep reporting the last value as if it were live. A quality field such as stale, bad, or uncertain can be more useful than repeating a number without explanation.

A working demo proves that data can move. A production-ready workflow proves that the data remains understandable when something goes wrong.

Closing thought

Node-RED is a practical tool for Modbus-to-MQTT workflows, but the real value is not just connecting two protocols.

The useful work is turning raw industrial values into structured, named, timestamped, and testable messages. MQTT does not make Modbus data cloud-ready by itself. The edge flow has to add the meaning.

A Robustel edge gateway EG5120 can support this kind of edge-to-cloud data workflow when the project needs industrial data access, Node-RED or Docker-based applications, Modbus and MQTT data paths, secure backhaul, and remote management.

The strongest takeaway is this: Modbus reads the field, MQTT carries the message, and Node-RED can help shape the meaning between them.

If you have worked on Modbus-to-MQTT data flows, I’d be curious to hear where the difficult part usually starts: register mapping, scaling, MQTT topic design, stale data handling, or keeping the flow maintainable after commissioning?

FAQ

Q1. How does Node-RED help with Modbus-to-MQTT workflows?

Node-RED can act as the flow layer between Modbus data collection and MQTT publishing. It can read selected Modbus values where the right nodes and configuration are available, map raw registers into meaningful tags, add equipment context, filter unnecessary updates, and publish structured MQTT payloads upstream.

Q2. Does MQTT automatically make Modbus data cloud-ready?

No. MQTT is a useful publish/subscribe transport, but it does not automatically make raw Modbus values meaningful. A register value still needs context such as tag name, unit, timestamp, asset ID, quality status, and topic structure before most IoT platforms can use it reliably.

Q3. Where does Robustel edge gateway EG5120 fit in this workflow?

Robustel edge gateway EG5120 fits into the site-side industrial edge gateway layer for selected Modbus-to-MQTT workflows. It can support Modbus TCP/RTU data paths, Docker-based edge applications, MQTT-to-cloud forwarding, cellular or Ethernet backhaul, secure communication, and remote gateway management. Final suitability still depends on the project configuration and validation process.

Top comments (0)