IMD SolutionComputing LibraryShop main store

Troubleshooting

Trace missing Modbus data from Node-RED to an MQTT cloud

Edge computing and IIoT Published 7 min read

Short answer

When a Modbus value never reaches the cloud platform, the payload format is almost never the fault. Prove the five hops in order — Modbus read, payload type, outbound broker session, credentials and client identity, then format, topic and timestamp — changing one thing per step, with a pinned debug node, a Test-NetConnection port check and QoS 1 PUBACKs as proof. The first hop that fails its proof is the fault; fix it before touching the next.

On this page
  1. The five hops a Modbus value must clear
  2. Hop 1: prove the Modbus read first
  3. Hop 2: turn the array into a number
  4. Hop 3: open the session to the broker
  5. Hop 4: check identity and credentials
  6. Hop 5: format, topic and timestamp
  7. Worked trace: holding register 40001 at 2540 counts
  8. When both payload formats fail the same way
  9. Questions asked

When a Modbus value never appears on the cloud platform, the payload format is almost never the fault. A platform's alternative payload formats share the same Modbus read, the same TCP/TLS session to the broker, and the same credentials, so a failure anywhere upstream of the format setting looks identical on the dashboard: no data. Walk the five hops in order — Modbus read, payload type, broker session, identity, then format and topic — changing one thing per step, proving each hop with a pinned debug node, a Test-NetConnection port check from the Node-RED host, and QoS 1 PUBACKs at the publish. The first hop that fails its proof is the fault; fix it before touching the next.

The five hops a Modbus value must clear #

A single value crosses five hops, and a silent failure at any of them looks the same at the cloud end.

Hop From To Failure that looks like "no data"
1 Modbus device Modbus-Read node Wrong unit ID, register type, address base or port; the read errors or returns a dead value
2 Modbus-Read node formatting or publish node Payload is an array or a string where a number is expected, so the message is dropped or arrives empty
3 Node-RED host broker over DNS, firewall and TLS The session never establishes; the node status never reaches connected
4 Broker authentication registered device identity CONNACK refusal or an endless reconnect loop
5 Broker platform ingestion Session up and publishes acknowledged, but nothing is mapped to the device

Work them in order and change one thing per step. If the number disappears between nodes inside the flow rather than at the cloud edge, fix MQTT sensor data missing in Node-RED covers those in-flow causes.

Hop 1: prove the Modbus read first #

Pin a static debug node to the Modbus-Read output and inspect both the array and the raw buffer before you add any conversion logic. Then check, in this order:

  • Target IP and port: 502 unless the device has been remapped.
  • Unit ID: the slave address the device actually answers on, not a default you assumed.
  • Register type: holding and input registers are separate address spaces.
  • Address base: many tools display 1-based addresses such as 40001, while Node-RED expects the 0-based offset.
  • Data type: a 32-bit value or a float spans two registers, and word order differs between devices.

The proof for this hop is a numeric payload in the debug sidebar that moves when the process value moves. An array that never moves means the read is wrong, and no MQTT setting will fix it.

Hop 2: turn the array into a number #

A Modbus read returns an array even for a single register, so the debug sidebar shows the value under index 0 before anything else happens. Publishing that array raw sends the wrong type to the platform. Add a change node that sets msg.payload to msg.payload[0], and for a multi-register read build one message per point instead of one message carrying everything.

The proof for this hop: a debug node after the change node shows msg.payload as a plain number that tracks the process value, with no brackets around it.

Hop 3: open the session to the broker #

Read the broker hostname and port from the platform's device registration screen; do not reuse values from another MQTT setup. Then test from the Node-RED host itself, not from an engineering laptop:

Resolve-DnsName <broker-host>
Test-NetConnection -ComputerName <broker-host> -Port <broker-port>

What each result means:

  • DNS fails: resolution is blocked or the host points at the wrong DNS server; fix DNS on the host or the plant gateway.
  • TcpTestSucceeded : False: a firewall or proxy blocks the outbound port. Request a rule for this one host and this one broker port — not an open network segment — and note that a plain HTTP proxy does not carry raw MQTT.
  • TCP succeeds but the TLS handshake fails in Node-RED: an inspecting firewall is replacing the certificate, the CA file is wrong, or the host clock is off. Exempt the broker from TLS inspection, load the CA the platform issues, and correct the system time.

The proof for this hop: the TCP test succeeds and the MQTT node status stays connected, with no repeating connect-and-disconnect cycle. If the same connect-and-drop pattern shows up on a controller-side client, fix a PLC MQTT client that never reaches your broker walks the same layer.

Hop 4: check identity and credentials #

A TCP connection that closes immediately after establishing is almost always an authentication or identity rejection, not a network fault. Copy the client ID, username, token or secret, and any certificate files from the device registration, and paste them without trailing spaces or line breaks. Two faults dominate this hop:

  • Duplicate client ID: a broker disconnects the older session when a second client connects with the same ID, so two Node-RED instances or a leftover test client produce an endless reconnect loop.
  • Mixed certificate material: the CA, client certificate and private key must come from the same registered device.

An independent MQTT 3.1.1 client run from the same host shows the refusal reason where the platform allows a test connection:

CONNACK code Meaning
1 Unacceptable protocol version
2 Client identifier rejected
3 Server unavailable
4 Bad username or password
5 Not authorized

The proof for this hop: the session stays connected for several minutes with no reconnect messages in the Node-RED log.

Hop 5: format, topic and timestamp #

Only now compare payload formats. Set one format, redeploy, and let it run a full publish interval before trying the other; switching formats while other settings are still changing makes the result unreadable. Check these against what the platform documents for the selected format:

  • The message arriving at the publish node carries the field names and types that format specifies.
  • The topic or device identifier is the one the platform assigned, not a free-text name.
  • The host clock is correct: a clock hours off produces samples the platform rejects or places outside the visible time window.
  • The publish interval is a reasonable period; pushing every Modbus poll cycle adds load without adding information.

MQTT QoS 0 carries no acknowledgement, so a publish the broker discards shows no error in Node-RED. While commissioning, set the publish to QoS 1 so a missing PUBACK appears in the log instead of silence. When the payload does reach a parser, nested JSON structures are their own silent failure; SCADA MQTT points blank with nested JSON payloads shows that mapping side in detail.

Worked trace: holding register 40001 at 2540 counts #

This is an illustrative case: every number in it is one you can read off the same screens.

Inputs:

  • The machine documentation lists the value at holding register 40001, 1-based, quantity 1, in unsigned 16-bit counts.
  • The debug sidebar after the Modbus-Read node shows msg.payload as [2540].
  • The broker host, port, client ID, username and token come from the platform's device registration screen.
  • The flow publishes on its configured interval.

Rule in words: Node-RED takes the 0-based offset, so subtract 40001 from a 4-series 1-based address; a quantity-1 read returns a one-element array; the number the platform must display is element 0.

Arithmetic:

  • Offset = 40001 - 40001 = 0, so the Modbus-Read node is set to address 0, quantity 1.
  • The read returns one element: msg.payload = [2540].
  • The change node sets msg.payload = msg.payload[0] = 2540 counts.

Trace with proofs: the debug number moves when the process value moves, so hops 1 and 2 are proven. Test-NetConnection -Port against the broker returns TcpTestSucceeded : True, so hop 3 is proven. The MQTT node stays connected across two publish intervals with a QoS 1 PUBACK logged for each publish, so hop 4 is proven. The platform's data view then shows 2540 with a timestamp that matches the Node-RED host clock, so hop 5 is proven.

Result: the value is on the platform, and the decision at each failure point:

  • The array never moves when the process value moves: stop at hop 1 — wrong register, unit ID or data type.
  • The number moves but TcpTestSucceeded : False: stop at hop 3 — the firewall rule.
  • The session is refused with CONNACK code 4 or 5: stop at hop 4 — credentials or authorization.
  • Every proof above is green and the platform still shows nothing for two full publish intervals: commit to hop 5 — format, topic or timestamp — and stop editing broker settings.

When both payload formats fail the same way #

Two payload formats share hops 1 through 4, so identical silence under both formats is itself a measurement: the fault sits upstream of format selection. Bring hops 1 through 4 to their proofs first, then try one format for a full publish interval, then the other. If both still fail with every proof green, delete and re-register the device and repeat the hop 4 and hop 5 checks against the new identity, because a stale registration is the one hop-5 fault that format settings cannot reach.

Questions asked

Can I run the broker port test from my engineering laptop to save time?

You can, but treat it as a clue, not proof. The path that matters starts on the Node-RED host. If the laptop reaches the broker port and the host does not, the block sits between the office network and the control network, and that tells the network team where the single host-and-port rule belongs. Re-run Test-NetConnection from the host itself before calling hop 3 done.

Why does the dashboard keep showing a value after my flow stops publishing?

Most platforms and brokers hold the last known value of a point, so a flat line is not evidence that data is flowing. Treat any value older than two publish intervals as stale: force a change at the source register and watch for it to appear within one interval. Where the platform offers a data-age or last-update alarm, enable it during commissioning so silence becomes a visible fault.

What QoS should the flow use in production once the path is proven?

Keep QoS 1 for anything you must not lose, such as batches, alarms and hourly totals, because every publish returns a PUBACK you can log. QoS 0 is reasonable for fast-changing telemetry where one lost sample costs nothing and the next poll replaces it. Never commission on QoS 0: with no acknowledgement, a publish the broker discards looks identical to success in Node-RED.

One message reached the platform and then nothing arrived. What does that pattern tell me?

A single success proves hops 1 through 4 worked at least once, so the configuration is broadly right and something broke mid-session. The leading cause is a second client connecting with the same client ID, which makes the broker drop your older session and puts both clients into a reconnect loop. Look for a duplicate Node-RED instance or a forgotten test client, then watch the node log for the repeating cycle.

Keep reading

  • Troubleshooting

    Fix MQTT sensor data missing in Node-RED

    A green MQTT connection in Node-RED proves only a broker session, not that the GSM module published a value or that the flow subscribes to its topic. An http in node cannot receive MQTT publications at all: use an mqtt in node. Trace RS-485 acquisition, publish result, broker identity and topic match in order, and fix the first stage with no positive result.

    Edge computing and IIoT

  • How-to

    Run Python and Node-RED beside PLC code on an edge PC

    Keep the IEC 61131-3 program in the controller runtime and run Python and Node-RED as separate Docker containers on the same edge PC. Exchange data over one MQTT interface with a fixed publish period, and declare data stale after three missed periods. One container per workload, and nothing from Python or Node-RED inside the control project.

    Edge computing and IIoT

  • How-to

    Sending PLC data to an IoT hub without custom software

    You do not need custom software to move PLC data to an IoT hub: a configurable edge package with an S7, Modbus TCP or EtherNet/IP driver, a channel mapping and an MQTT publisher replaces hand-written acquisition code. Verify two things before you commit: the driver covers the protocol your controller actually speaks, and the publisher covers the destination's authentication and message format. Software still does the work — you configure it instead of writing it.

    Edge computing and IIoT