IMD SolutionComputing LibraryShop main store

Comparison

MQTT versus Modbus TCP on a local plant network

Edge computing and IIoT Published 8 min read By IMD Solution engineering team

Short answer

On a reliable local network reading one addressed device, choose Modbus TCP: it runs natively in the control runtime and drops the Node-RED client, the internal API hand-off and the remote broker that MQTT needs. Choose MQTT only when username-password and topic-based access control justify those extra layers; neither path is proven more reliable or lighter at equal refresh rates.

On this page
  1. Which protocol should read local data from one device?
  2. What does each protocol add to the data path?
  3. How do the access controls compare?
  4. Who defines the data model: registers or topics?
  5. How do you notice a dead link with each protocol?
  6. What does the choice cost at the same refresh rate?
  7. When does MQTT win even on a local network?
  8. How do you verify the path before you trust it?
  9. Questions asked

Your edge controller needs one set of values from one device on the plant network, and that device can act either as a Modbus TCP server or as a small MQTT broker. Choose Modbus TCP. It runs natively in the control runtime, so each value crosses a single TCP exchange with no broker, client or script in between; the MQTT route adds a client in Node-RED, an internal API hand-off, a broker on the remote device and a publisher feeding it. MQTT earns those layers only when username-password and topic-based access control are requirements. Here is the comparison layer by layer, with a worked cost example and the decision for each case.

Which protocol should read local data from one device? #

Modbus TCP, whenever the network is local and reliable, you read one addressed device, and the segment is trusted: the protocol runs natively in your control runtime and nothing sits between the controller and the device. The case for it is subtraction. The MQTT alternative is four cooperating pieces — a publisher on the remote device, the broker it feeds, the MQTT client in Node-RED on your controller, and the internal API that copies each value into the runtime — and every piece is software you install, configure, monitor and patch. On a link you already trust, none of those pieces buys anything you need, and none of them is proven more reliable than the native poll it replaces. MQTT's real advantages, credentials and one-to-many delivery, pay for their layers only in the cases at the end of this article.

What does each protocol add to the data path? #

Modbus TCP crosses one exchange: a client inside the control runtime sends a read request and the device's server answers on the same TCP connection, with no broker, gateway or script in between. That is the whole path, and it is why the values land directly in controller tags. MQTT cannot work that way — it cannot run controller to device at all, since every message passes through a broker, as why MQTT needs a broker and cannot run PLC to device sets out. On your controller the MQTT side lives in Node-RED, and values reach the runtime only through the internal API — the same broker-versus-direct-transport trade walked through in MQTT broker versus direct TCP from a Node-RED edge device.

Decision factor Modbus TCP MQTT with the broker on the remote device
Where it runs in the controller Native client in the control runtime Client in Node-RED; values copied into the runtime through the internal API
Software in the path Two stacks: runtime client, device server Four stages: device publisher, broker, Node-RED client, internal API
Access control None; any host reaching port 502 can read and write Username and password at connect; accounts limited to named topics
Data model Fixed: numbered coils and holding registers Yours to write: topics, encoding, scaling, timestamps
Failure visibility Every poll answers or times out Silence is ambiguous until you add a heartbeat
Encryption Not in the protocol Not in plain MQTT; TLS goes on the broker listener
Best fit Local network, one device, trusted segment Untrusted hop, per-device credentials, several consumers

How do the access controls compare? #

This is MQTT's one real edge locally: MQTT 3.1.1, the OASIS standard, lets the CONNECT packet carry a username and password and leaves the check to the broker, and broker accounts can be limited to named topics, while Modbus accepts every query. Modbus TCP has no authentication at all. The Modbus Messaging on TCP/IP Implementation Guide reserves TCP port 502 and defines no credentials, so any host that reaches that port can read every coil and register — and write them, because the write function codes are as open as the reads. Give the controller a read-only account on a data topic in MQTT and it cannot command anything; give a host a route to a Modbus server and it can. One safety note: an open write path means any host on that segment can move a register that commands an output, so that port stays inside the control VLAN and is never forwarded or mapped past it. Against that, weigh the four stages MQTT costs on a segment you already trust.

Who defines the data model: registers or topics? #

Modbus hands you the application model ready-made: numbered coils and holding registers — registers 16 bits wide — that standard function codes read and write, so the device's register map is the entire contract. MQTT is only a messaging protocol, not an application protocol: it delivers bytes to a topic and leaves the frame to you — topic names, payload encoding, scaling from integer to engineering units, timestamps, and what a bad-quality value looks like. Two MQTT implementations will not interoperate until that frame is documented, and you become the author of a small spec. If you go MQTT anyway, either write that spec before the first publish or adopt a defined industrial profile such as Sparkplug B, and fix the Sparkplug B group, edge node and device ID naming up front. With a device that already has a Modbus register map, choosing Modbus means the data-model work is already done.

With Modbus you see a dead device at the next poll: the request either answers or times out, so the fault surfaces within one refresh period plus the timeout setting, with no extra code. MQTT inverts this. The publisher pushes, the controller listens, and silence is ambiguous — no message can mean the value did not change or that the publisher, the broker or the Node-RED client died. A push architecture reports changes, not liveness, so you must build liveness yourself: have the device publish a counter or timestamp on a fixed period, and flag the data stale after two missed heartbeats, for example. That is one more piece of the MQTT path to design, test and maintain. Skip it and you get the classic green-screen failure: values frozen at the last publish while every status looks healthy, the symptom traced in MQTT values that only update on refresh. Modbus gives you that alarm for free with every poll.

What does the choice cost at the same refresh rate? #

At one device and one poll per second, neither path loads PC-class hardware measurably, so wire cost does not decide this question; what decides it is the number of stages each refresh crosses. Worked example, illustrative inputs: one block of eight holding registers, refreshed on a 1000 ms period, for one hour.

  • Modbus path: one request and one reply per period. 1 exchange/s × 3,600 s = 3,600 exchanges, each on the same TCP connection.
  • MQTT path: every refresh passes four stages — device publisher to broker, broker to the Node-RED client, client to the internal API, API into the runtime. 3,600 × 4 = 14,400 stage transfers in that hour.
  • Difference: 14,400 − 3,600 = 10,800 extra hand-offs, and every hand-off is code that can buffer, delay or drop the value.

Both paths pass that load easily on industrial PC-class hardware, so do not choose on bandwidth or CPU. Do measure before believing any footprint claim: a broker's cost grows with connection count and retained messages, and broker integrations have been reported to eat heavy CPU and memory once they grow, while a 1 Hz poll stays flat. The honest statement is that neither protocol is proven more reliable or lighter at equal refresh rates — the difference you can count is the three extra stages MQTT puts between the device and your tag.

When does MQTT win even on a local network? #

Choose MQTT when the link crosses a segment you do not fully trust, when more than one consumer needs the same values, or when many devices publish only on change — those are the problems a broker with credentials and fan-out solves. An untrusted hop is the clearest case: per-device credentials, topic permissions and a TLS listener are worth every extra stage there. Several consumers is the second: a broker delivers one publish to every subscriber, while a Modbus server answers each client with its own polls — when one Modbus TCP server can serve two clients depends on the server's connection limit, and three or four clients multiply the polling. Report-by-exception is the third, and it needs scale: with one device it saves nothing and still costs you the heartbeat. None of the three applies to one trusted link reading one device, which is why that case goes to Modbus.

How do you verify the path before you trust it? #

Prove the chosen path end to end at the required refresh rate, then break each stage on purpose and confirm the controller's reaction, because that test is where the extra MQTT stages either earn their keep or show their seams.

  1. Modbus first: read a known register from the runtime and confirm the value changes with timestamps matching the refresh period.
  2. Pull the device's cable and confirm the runtime raises a fault within one refresh period plus the timeout, then clears it on reconnect without a restart.
  3. MQTT path: publish a test value, confirm the Node-RED client receives it, and confirm the internal API writes it into the controller tag — check all three points, not just the ends.
  4. Stop the broker and confirm the heartbeat logic flags stale data within the misses you defined, and that no screen keeps showing the last number as live.
  5. Record every failure with its layer — broker, client, API, runtime or device — so a stall in one piece is never misfiled as a protocol reliability problem.

The decision, case by case. Local network, one addressed device, trusted segment: Modbus TCP — the native client polls and there is nothing else to justify. Untrusted hop, per-device credentials, or several consumers: MQTT with a TLS listener and restricted accounts, and you accept the client, the API hand-off and the broker as the price of that control. Anything between those two: run the cable-pull and broker-stop tests on both paths at your refresh rate, and the stage count settles it.

Questions asked

Does MQTT encrypt the username and password it sends?

Not by itself. Plain MQTT 3.1.1 carries the username and password inside the CONNECT packet as readable text, so anyone capturing the wire sees them; TLS on a separate broker listener is what hides them. On a fully trusted control segment the plain listener is an accepted trade, but never run credentials that way across a link you do not control.

Can I limit who writes to a Modbus TCP device without changing the protocol?

Only at the network layer. Place a stateful firewall rule in front of the device that permits TCP port 502 from the controller's address alone and denies every other source, and keep the device off any routable segment. The protocol will still execute any write that gets through, so that rule is the entire access control.

What happens to each path after the remote device reboots?

A Modbus server answers again as soon as its stack is up; the runtime's polls time out during boot and recover by themselves. On MQTT the subscriber reconnects on its own, but the controller holds the last value until the publisher reconnects and publishes, so publish current state on connect or retain it, or the display shows stale data indefinitely.

Can I run both paths side by side while I decide?

Yes, and it is the safest way to decide. Keep the native Modbus poll live while the MQTT path is built in Node-RED, log both streams with timestamps, and compare them across a device reboot, a broker stop and normal production. Cut the logic over only after the MQTT stream has matched values and fault behavior for a full production cycle.

Keep reading

  • Explainer

    Edge gateway Modbus TCP polling over the WAN port

    When a data gateway supports MQTT as a client only, drop the broker hop: configure the Modbus TCP poll to target the device's IP address in the same subnet as the gateway's WAN interface. The gateway opens the TCP connection itself, so polled values keep updating with the internet link down. Verify by pulling the uplink and watching one known register.

    Edge computing and IIoT

  • Troubleshooting

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

    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.

    Edge computing and IIoT

  • Troubleshooting

    Why an MQTT app rejects a broker hostname and needs an IP address

    The installed release of the app validates its MQTT address field as numeric only, so a broker hostname is rejected before any packet leaves the controller. Resolve the name and enter the numeric address with port 1883, SSL Protocol set to None and Certificate set to None for the plain public listener; the reported test connected exactly that way. The failed connection to the local broker is a separate listener, TLS and credential fault the public test does not touch.

    Edge computing and IIoT

Node-RED visual flow vs YAML on the plant floor