IMD SolutionComputing LibraryShop main store

Explainer

Edge gateway Modbus TCP polling over the WAN port

Edge computing and IIoT Published 6 min read

Short answer

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.

On this page
  1. Why the MQTT hop fails when the internet link is down
  2. The decision: poll Modbus TCP through the WAN interface
  3. Worked addressing example
  4. What to change in the gateway configuration
  5. Keep the poll off the internet
  6. Proving the design with the uplink pulled
  7. When a local broker still makes sense
  8. Questions asked

When an edge gateway supports MQTT only as a client, an internet-hosted broker turns into a single point of failure for data acquisition: pull the uplink and the polled values stop, even though the gateway and the Modbus TCP device sit on the same plant network. The fix is to remove MQTT from the acquisition path entirely. Point the gateway's Modbus TCP poll directly at the device's IP address, in the same subnet as the gateway's WAN interface, and the gateway opens the TCP connection locally. Values then keep updating with the internet down. Confirm it by pulling the uplink and watching one known register change.

The design that fails looks like this: a Modbus TCP device sits on the WAN-side segment, a separate translator converts its Modbus TCP data to MQTT, and the broker lives on the internet. The gateway, as an MQTT client, subscribes to the broker and reads the values back from there.

Every value now crosses a chain of four hops: Modbus read from the device, translation to MQTT, publish across the internet to the broker, and delivery back down to the gateway client. Any break in the internet leg kills the chain. The gateway and the device are neighbours on the same cable plant, but the data between them travels out to a server and back.

That is the core constraint, and it is not fixable inside a client-only gateway: such a gateway can publish and subscribe to a broker, but it cannot accept client connections or host subscriptions itself. Where the broker should live when you genuinely need one is a separate architecture question; the trade-offs are laid out in running an MQTT broker in the PLC or on a separate device.

The decision: poll Modbus TCP through the WAN interface #

A gateway that already has a Modbus TCP polling engine does not need the MQTT path for acquisition. Set the poll target to the device's IP address, in the same range as the gateway's WAN address, and the gateway establishes the connection itself through its WAN port. Nothing routes through the internet, so an outage there cannot stop the data.

Design Acquisition dependency Behaviour when the internet is down
Modbus TCP device, translator, internet broker, gateway as MQTT client TCP session to the remote broker Acquisition stops; polled values freeze
Gateway polls Modbus TCP directly through its WAN port Local TCP session on the WAN segment Polling continues unchanged

If MQTT is still wanted for a second consumer, keep it as a parallel publishing path, not as the acquisition path. The gateway polls Modbus TCP locally and, independently, publishes to the broker when the uplink is up. Acquisition becomes immune to the broker; only the remote consumers are affected by an outage.

Worked addressing example #

Take a gateway whose WAN interface is set to 192.168.10.10 with subnet mask 255.255.255.0. That is a /24 network, 192.168.10.0, with usable host addresses from 192.168.10.1 through 192.168.10.254 (the .0 address names the network and .255 is the broadcast address).

The Modbus TCP device sits at 192.168.10.25, listening on the standard Modbus TCP port 502. Both addresses share the first three octets, so the device is inside the WAN subnet and reachable directly through the WAN port.

Configure the poll for 10 holding registers, function code 3, starting at register 40001, on a 5 second cycle. Each read carries 10 registers times 2 bytes, or 20 bytes of application data, over one TCP connection the gateway reuses, giving 12 reads per minute. All of that traffic stays on the local segment. If the device address were instead 192.168.20.25, outside the WAN subnet, this layout would not work: the gateway has no established route from its WAN interface into other subnets, so re-address the device into the WAN subnet or confirm the gateway documents a static route on that interface before relying on the poll.

What to change in the gateway configuration #

One change, in one place. In the gateway's Modbus TCP polling definition, the same screen where you already set the function code, register address and cycle time, set the target to the device's IP address and its Modbus TCP port. Leave the rest of the definition as it is.

No port forwarding, NAT or WAN-to-LAN transfer rule is involved in this layout, because the gateway initiates the connection outbound through its own WAN port. If your earlier design used a forwarding rule to reach the device, remove it rather than leave both paths active.

Keep the poll off the internet #

Modbus TCP has no encryption and no authentication, so anyone who can reach port 502 on the device can read and write its registers. Keep the device and the poll strictly on the plant-side segment behind the router, and never forward that port from the internet to the device. Remote access to the gateway should go through the gateway's own authenticated tunnel, not an opened port on the router.

The whole point of the change is behaviour during an outage, so test exactly that:

  1. Pick one register on the device whose value changes on its own, and note its last polled value and timestamp in the gateway.
  2. Disconnect the internet uplink at the router, so the WAN segment stays up but nothing reaches the internet.
  3. Wait through several poll cycles, several times the 5 second cycle in the example, and confirm the register value in the gateway still changes and the timestamps keep advancing.
  4. Reconnect the uplink and confirm the gateway's independent MQTT publish path, if you kept one, resumes.

If the value freezes while the uplink is down, the acquisition path still depends on the broker connection. That points back to the poll target: check that it is the device's own address inside the WAN subnet, not an address reached through the internet. Reachability problems of this kind, where a test to one hop passes but the real connection fails, follow the same diagnostic pattern as why a device cannot publish MQTT to a broker on your PC.

When a local broker still makes sense #

Sometimes several consumers on the plant network want MQTT feeds, and an internet broker is the wrong place for them too. Run a broker on a separate always-on machine inside the plant network, and let the gateway publish to it as a client; the acquisition poll stays direct Modbus TCP either way. A broker is lightweight, and a fanless industrial mini PC mounted next to the gateway in the cabinet is enough to host one. Keep the two paths distinct in your documentation: the local poll is the acquisition guarantee, the MQTT publish is a distribution convenience, and only the second one is allowed to disappear when the uplink does.

Questions asked

Can an MQTT-client-only gateway also run the MQTT broker?

No. A gateway identified as an MQTT client connects out to a broker; it does not accept client connections or store subscriptions. If a local broker is genuinely needed in the design, run it on a separate always-on device on the plant network, and let the gateway publish to it as a client. The acquisition path itself does not need a broker at all when the gateway can poll Modbus TCP directly.

Does the Modbus TCP device have to be in the same subnet as the gateway's WAN address?

Yes, for the layout that works without extra configuration. The documented behavior is that a poll target set to an address in the same range as the gateway's WAN address is reached directly through the WAN port. An address in a different subnet has no established route from that interface, so either move the device into the WAN subnet or confirm the gateway documents a static route before relying on it.

Is any port forwarding or WAN-to-LAN rule needed for this polling?

No. The gateway initiates the Modbus TCP connection itself, outbound through its WAN port, so no forwarding, NAT or transfer rule is involved. Set the poll target to the device's IP address and Modbus TCP port in the gateway's polling configuration, and nothing else in the gateway needs to change. If values do not arrive, check the addressing and the device's register map, not the router.

How do you prove the polling survives an internet outage?

Record the last value and timestamp of one register on the device that changes on its own, disconnect the internet uplink at the router, wait through several poll cycles, and confirm the gateway still shows the value changing. Reconnect the uplink afterwards.

Keep reading

  • How-to

    MQTT to Modbus TCP with Node-RED on an edge gateway

    Yes: Node-RED with the node-red-contrib-modbus package can serve MQTT data to a SCADA client as Modbus TCP. Read the RTU device in Node-RED first, give the Modbus server node a port nothing else owns, and scale each MQTT payload to one integer per holding register before the first end-to-end test.

    Edge computing and IIoT

  • How-to

    Bridging OPC UA PLC data to MQTT with an edge PC

    Keep the OPC UA server on the PLC side and give MQTT publishing its own role on a separate edge PC that acts as the OPC UA client and MQTT publisher. Commission the two links independently — first a verified tag read, then a verified subscriber message — and only then widen the tag set.

    Edge computing and IIoT

  • Explainer

    When one edge PC can host the MQTT broker for the rest

    Yes: MQTT is publish-subscribe over plain IP reachability, so one edge PC can host the broker for the whole cell and every device needs only a TCP path to that one address. The design work is per connection: protocol version, QoS, TLS, retained messages and the last will. Verify each client's path and the failure behavior, not the broker app.

    Edge computing and IIoT