IntegrationNode-RED Modbus Example
Modbus → MQTT Bridge
Forward Modbus register values to an MQTT broker so other systems (dashboards, cloud platforms, other PLCs) can subscribe. This pattern is common in IIoT gateways. The example polls one register every 10 seconds and publishes it to a topic.
What you need
- Node-RED v3+
- node-red-contrib-modbus installed
- An MQTT broker accessible on the network (e.g. Mosquitto, HiveMQ, or cloud broker)
Flow Overview
Modbus Device Node-RED MQTT Broker
│ │ │
│◀── FC03 poll ────────────│ │
│─── 4 registers ─────────▶│ │
│ │── scale + format ──▶ publish ──▶│
│ │ topic: factory/ │
│ │ line1/temp │
│◀── subscribed clients ───────────│
Node-RED Flow JSON
To import: open Node-RED → Hamburger menu → Import → paste this JSON → Deploy.
Expected Output
// MQTT message on topic 'factory/line1/temperature':
{ topic: "factory/line1/temperature", payload: 24.5 }Common Gotchas
- Apply scaling in the function node — raw register values are rarely the engineering unit directly.
- Use QoS 1 for important process values to ensure delivery even if the broker restarts briefly.
- For many registers, build one message per register in a loop and return msg array from the function node.
- If Modbus polling fails, the MQTT retain flag means subscribers keep seeing the last known good value — consider publishing NaN or a status flag on error.
- Use a change node to suppress publishing when the value has not changed (deadband filtering).
Same in ModPackQT — in 30 seconds
ModPackQT has a built-in MQTT integration that publishes Modbus register values on configurable topics — no Node-RED flow needed. Configure topic, scaling, and deadband in the MQTT tab.
Was this example helpful?
More Integration examples