IMDTouchKnowledge BaseShop main store

How-to

Getting gateway sensor data onto an HMI with a Modbus TCP bridge

Industrial networks Published 7 min read

Short answer

An HMI cannot poll a Node-RED application, so put the sensor values into a Modbus TCP server with a fixed register map and point the HMI's client driver at that server on TCP port 502. Run the server in the gateway's Node-RED when its runtime accepts the Modbus package; otherwise run it on a separate host. Add a heartbeat and a data-age register so the display can tell fresh values from retained ones.

On this page
  1. Why the HMI cannot read Node-RED directly
  2. Choose the host that runs the Modbus server
  3. Build the bridge and the register map
  4. Worked example: one temperature in two registers
  5. Keep stale data honest
  6. The decision for each case
  7. Questions asked

Sensor data reaches a Node-RED application through an industrial gateway, and the HMI panel has no driver that can read Node-RED. Give the HMI a driver it does have: a Modbus TCP server whose registers mirror the sensor values. Run that server in the gateway's Node-RED when its runtime installs the Modbus package, and on a small separate host when it does not. The HMI's Modbus TCP client driver polls the server, a fixed register map decides what every register means, and a heartbeat plus a data-age register tell the operator whether the numbers on screen are current. The steps below cover the roles, the host choice, the register map, the float word order and the acceptance checks.

Why the HMI cannot read Node-RED directly #

Modbus TCP gives every device one of two roles: the client opens the connection and issues reads and writes, the server holds the data and answers. An HMI panel's Modbus TCP driver is a client — it polls and never serves. A Node-RED application collecting sensor messages over MQTT or HTTP is neither: nothing in it answers a poll. The bridge therefore has one job — run a Modbus TCP server in or beside Node-RED, keep a register map in step with the arriving messages, and let the HMI poll it. The Modbus specification puts Modbus TCP on TCP port 502; keep that port closed to everything else on the machine network. Which side initiates decides whether anything works at all, and the HMI Modbus TCP client and server roles page works through the split for a panel with no driver for the far end.

Choose the host that runs the Modbus server #

Check the gateway before you design around it. The Node-RED flows that collect sensor data run the same on an old runtime as on a new one, but the Modbus server package needs a runtime new enough to install and deploy it, and gateways in this class often ship a build that cannot. A package that fails to install, or a node that never deploys, is a runtime limit — not a network fault, and not a reason to start debugging the HMI driver.

Host Choose it when Watch for
The gateway's own Node-RED The Modbus server package installs and deploys there One process now does acquisition and display service together
A separate host next to the gateway The package will not run on the gateway, or the gateway must not carry display traffic One more device to power, address and back up
The HMI panel itself Its communications manual lists a Modbus TCP server mode plus a way to keep the map updated Most panel runtimes offer no scripting environment for that

When the gateway cannot host it, put the bridge on a small computer that lives in the cabinet — an industrial mini PC is enough for a Modbus server and a conversion flow — and forward the sensor messages to it. If that host also has to poll another Modbus device as a client over its single Ethernet port, that dual-role combination has rules of its own: the Modbus TCP dual-role setup on a single Ethernet port page covers running a client and a server on one port. Decision in one line: gateway when the package installs, separate host when it does not.

Build the bridge and the register map #

Agree the map before anyone opens a tag browser. The Modbus specification caps a single read at 125 holding registers, so one poll covers any map of this size.

  1. Confirm the HMI side. Add the Modbus TCP driver in the HMI engineering tool and check its manual: the driver is the client. Enter the server host's address, for example 192.168.1.50, the Modbus TCP port, and the unit ID the server node is configured with, commonly 1.
  2. Install the server node. On the chosen host, add a Modbus server node for Node-RED — the commonly used package is node-red-contrib-modbus — and size it to the map; ten holding registers covers the example below with room for the next sensor.
  3. Fix the register map in writing. Every value gets an address, a type, a scaling and a word order, identical in the flow and in the HMI project; the example map is in the table under these steps. Protocol addresses begin at 0, and tag browsers that show 40001-style names point at the same registers — the holding register address conventions page untangles numbers like 4500001.
  4. Write the conversion flow. Validate each sensor message, convert the value to the mapped representation, write the value registers, add one to the heartbeat counter, and let a repeating one-second trigger refresh the data-age register. A malformed message must never write a zero into a value register: reject it and let the age register show the gap.
  5. Configure the HMI tags and the word order. Build the tags from the same map, set the driver's 32-bit word order to match it, and give the operator the data age as a number with a stale flag; on a 5-second sensor publish interval, a workable example limit is 15 seconds — three missed intervals.
  6. Commission on a bench. Inject a known sensor value, then stop the upstream feed, then cut the link between HMI and bridge — one change at a time, against the acceptance checks at the end.
Register (protocol address) Content Representation
0–1 Temperature 32-bit IEEE 754 float, low word first
2 Heartbeat counter 16-bit unsigned integer, adds 1 per accepted sensor message
3 Data age seconds since the last accepted message, rewritten every second
4 Reserved the next sensor

Worked example: one temperature in two registers #

The sensor reports 23.47 °C. The nearest 32-bit IEEE 754 float is 0x41BBC28F, so the flow splits it into the high word 0x41BB, decimal 16827, and the low word 0xC28F, decimal 49807. The map says low word first: register 0 gets 49807 and register 1 gets 16827.

Now set the driver's word order the wrong way round and read the same two registers: 49807 and 16827 combine high word first into 0xC28F41BB. The sign bit is 1, so the value is negative; the exponent field reads 10000101 in binary, which is 133, and 133 − 127 = 6 gives a scale of 2^6 = 64; the mantissa is 999867 out of 8388608, or 0.1192, so the driver computes (1 + 0.1192) × 64 ≈ 71.63 and the display shows about -71.63 °C. Same wire, same bytes, wrong order.

Set the word order back to match the map, re-read, and the display returns to 23.47. A value that comes out wrong by orders of magnitude is word order, offset or signedness almost every time: fixing Modbus TCP addressing errors between an HMI and a PLC walks the usual suspects, and displaying a PLC Real value over Modbus on an HMI covers the word-order setting from the panel side.

Keep stale data honest #

A Modbus TCP server answers every poll with whatever sits in its registers, whether or not the sensors still feed it. Through an upstream dropout the HMI keeps reporting a healthy link and keeps displaying the last temperature with the same confidence as a live one — nothing on the wire separates them. The map carries the separation instead: the heartbeat stops advancing the moment messages stop arriving, and the data-age register climbs. Drive the stale flag on the display from the age, never from the driver status.

Run the two failure checks separately on the bench. Stop the sensor feed and leave the bridge running: the age must climb past the limit and raise the flag while the driver still reports a healthy link. Then cut the link between HMI and bridge: the driver must report the loss on its own timeout instead of freezing the screen, and nothing it retained may reappear as current after the link recovers. When the sensor feed resumes, the jump in the heartbeat counter shows how the bridge caught up.

The decision for each case #

Gateway can install and deploy the Modbus server package: bridge on the gateway — one device, one flow. Gateway cannot: bridge on a separate cabinet host, with the gateway keeping acquisition and forwarding the messages. Either way, the register map is written down once and both sides read from it, one poll covers the whole map, and the data age decides what the operator may trust on screen. Keep the entire map read-only to the HMI: a display link has no business writing to process data, and a control write through this bridge is a new safety design, not a tag setting.

Questions asked

Can the HMI read the Node-RED application directly?

Only if the panel ships a driver for a protocol the Node-RED application actually serves, which panel HMIs rarely do. Modbus TCP drivers on HMI panels act as clients and can only poll a server, so the general answer is to publish the sensor values into a Modbus TCP server register map and poll that. The bridge is a small flow, and it keeps the HMI project independent of how the sensors reach the gateway.

The HMI connects but the number is absurd. Where do I look first?

At the word order of any 32-bit value. Read the two raw registers as unsigned integers and combine them in both orders, then compare each result with the value the sensor sent. In the worked example, 23.47 degrees Celsius displayed as about -71.63 when the driver combined the words backwards; setting the word order to match the map restored the correct reading.

Which address, port and unit ID do I enter on the HMI?

The address of the host running the Modbus TCP server, for example 192.168.1.50; TCP port 502, the standard Modbus TCP port; and the unit ID the server node is configured with, commonly 1. Register addresses follow the shared map, and remember that some HMI tag browsers display protocol address 0 under a 40001-style name.

How do I stop the panel showing old values after a sensor dropout?

Carry freshness in the data itself. A heartbeat register adds one per accepted sensor message and a data-age register counts the seconds since the last accepted message, refreshed every second. Drive a stale flag on the display from that age; in the example map the limit is 15 seconds on a 5-second publish interval. The Modbus link looks healthy throughout a dropout, so the age register is the only honest signal.

Keep reading

  • How-to

    How to Send String Data Over Modbus Between an HMI and a Gateway

    Modbus defines only coils and 16-bit registers, so an HMI cannot write a native string tag to a gateway. Pack the text as two ASCII characters per holding register, agree byte order and a length word at both ends, and rebuild the text in a gateway script before it is applied.

    Industrial networks

  • Troubleshooting

    Why a Modbus coil read fails when the request block is too long

    Exception 02 on a Read Coils exchange means the server checked every address from the start through start + quantity - 1 and found one outside its coil map, so it rejected the whole read. When a client that reads full bytes asks for 8 coils from a device that maps only 4, the first four coils in an easyE4 base unit, the valid start address still fails. Cut the quantity to fit the map; in HMI Droid that is the "Always read full bytes" setting.

    Industrial networks

  • Explainer

    Why Modbus RTU over Ethernet is not Modbus TCP for an HMI

    An Ethernet port carries bytes, not a protocol. A PLC that tunnels Modbus RTU frames over Ethernet answers only frames carrying a slave address and a CRC, while an HMI Modbus TCP driver sends MBAP frames with no CRC, so the two never parse each other. Match the driver to the PLC's documented packet format, verify the driver's transport support, and put a translating gateway between them when the formats differ.

    Industrial networks