Troubleshooting
Fix a PLC MQTT client that never reaches your broker
Short answer
Most PLC MQTT failures sit in one of three stages: the broker listener, the network path to the port the client is actually configured for, or the client's own publish logic. Test in that order; a connect timeout points to the first two, a silent publish to the third.
On this page
- Sort the symptom into three stages
- Stage 1: prove the broker listens on the plant interface
- Stage 2: test the path to the configured port
- Stage 3: prove the publish actually runs and the topic matches
- Worked example: broker at 192.168.10.20 on port 1883, controller in 192.168.20.0/24
- Where the MQTT client should live
- The fix, in order
- Questions asked
Split the failure into three stages and test them in order: the broker's listener, the network path to the port the client is actually configured for, then the client's own publish logic. A connect timeout lives in the first two stages. A client that connects cleanly but whose messages never appear lives in the third. Most of these hunts end at the path: the client was pointed at port 1883 or 8883 because those are the conventional MQTT ports, and nobody verified that the broker's configured listener answers on that port from the controller's subnet. And you do not need a special module to get PLC data onto MQTT — you need a verified listener, one open port and a publish that actually executes.
Sort the symptom into three stages #
Map what you observe to a stage before changing anything, and work the stages in order: publish logic cannot be debugged honestly over a path that drops every connect, and the listener cannot be blamed for a timeout the firewall caused.
| What you observe | Stage to work | What it usually means |
|---|---|---|
| Connect times out, retries, times out again | 1, then 2 | Nothing is listening at the address and port you assume, or the port is filtered |
| Client connects, broker log shows the session, but no message arrives | 3 | The publish is not triggered, or the topic does not match |
| A workstation reaches the broker, the controller never does | 2 | Routing or firewall policy differs per subnet |
| The broker drops the client minutes after connect | 3 | The client goes silent past its keepalive window |
Stage 1: prove the broker listens on the plant interface #
A broker that is installed and usable from its own workstation proves nothing about the plant path. Since Mosquitto 2.0, a configuration that defines no listener accepts connections from the local machine only, so a test tool running beside the broker succeeds while every remote client times out. Define a listener bound to the plant-facing interface and set authentication to match what the client sends. The broker side of this, including the listener and the access rules, is walked through in Run a secure Mosquitto MQTT lab broker with Node-RED.
Turn broker logging on and watch for the controller's address. No attempt from that address in the log means the request never arrived — go to stage 2. An attempt that arrives and fails means credentials, authorization or protocol settings, fixed at the broker.
One more stage-1 control: run a TCP connect test to the configured port from a machine on the broker's own subnet. If that cannot complete, stop here — the listener is wrong, and no firewall change will help.
Stage 2: test the path to the configured port #
Read the port out of the client configuration rather than assuming it. Ports 1883 (plaintext) and 8883 (MQTT over TLS) are conventions, not facts about your broker; the listener definition is the only truth. This is the single most common miss in this failure class: the port was never verified as open, the topic and payload were edited instead, and nothing could have worked.
Test from the controller's subnet, not the office — a PC on the broker's subnet says nothing about the controller's path, because routing and firewall policy are per subnet. Move a laptop onto the controller's subnet, or run the test from anything that shares it, and read the signatures:
- Ping to the broker address fails: routing first, port later.
- Ping answers but the TCP connect to the configured port times out with no reply: a firewall is silently dropping the port.
- The connect is refused within milliseconds: the host is reachable and nothing is listening on that port — return to stage 1.
- A packet capture on the controller (Wireshark works) shows the SYN leaving and no SYN/ACK returning: the drop sits between the subnets.
Then open exactly the configured port, from the controller's source subnet, through your site's change process — never a broad allow — and keep plaintext 1883 inside the segmented OT network. A blocked path is not fixable by editing the topic or the payload.
Stage 3: prove the publish actually runs and the topic matches #
A successful connect is not a successful publish. Check, in this order:
- The trigger. Confirm the publish call executes inside your test window — the rung or condition that invokes it is actually true when you expect. The controller sitting in Run proves the project runs, not that the publish fired.
- The status output. Read the completion and error status the client library documents instead of inferring success from the absence of a fault.
- The topic, byte for byte. Case, leading slashes and level count must match on both ends; a subscriber on
plant/line1/temperaturenever seesplant/Line1/Temperature. Wildcards (+,#) belong in subscriptions only, never in a published topic.
Then split the two ends with a known-good receiver: subscribe to # on the same broker with a test client and trigger the publish. If the wildcard subscription shows the message, the publisher and path are fine and the real subscriber's filter is wrong — the receiving-side checks in Fix MQTT sensor data missing in Node-RED take over from there. If the wildcard subscription shows nothing, the message never reached the broker and you are still in stages 1 or 2. A complete reference path, gateway to broker to Node-RED with both ends verified, is described in how gateway data reaches Node-RED through an MQTT broker.
Worked example: broker at 192.168.10.20 on port 1883, controller in 192.168.20.0/24 #
Inputs. Broker 192.168.10.20 with its listener on TCP 1883 — the conventional MQTT port this failure class assumes; controller subnet 192.168.20.0/24 and broker subnet 192.168.10.0/24 — illustrative plant addressing; client connect timeout 15 s — the default of one common client library, so confirm your own library's setting; retry cycle 60 s — the pattern behind a timeout roughly every minute; a laptop moved into 192.168.20.0/24 running ping and TCP connect tests.
Rule. A connect test that fails only on the broker's port, while ping to the same address answers, proves the route is up and the port is filtered. The timeout value belongs to the client's own retry budget, not to the broker's response time.
Arithmetic.
- Ping from the controller subnet: five replies at about 1 ms round-trip — the route between subnets is up.
- TCP connect to 192.168.10.20:1883 from the same laptop: SYN leaves, no SYN/ACK returns, the client gives up at 15 s. A closed port would answer RST in about 1 ms, so 15 s of silence means the port is filtered, not closed.
- The same connect from the broker's own subnet: completes in single-digit milliseconds — the listener is fine locally.
- Retry budget: 15 s wasted per attempt ÷ 60 s cycle = 15/60 = 0.25, so 25 percent of every cycle is dead wait on a reply the firewall never forwards — one timeout roughly every minute.
- Broker log across those timestamps: no attempt from any 192.168.20.x address, so the drop sits between the subnets, not at the broker.
Result. Route good, listener good, TCP 1883 filtered at the inter-subnet boundary.
Decision. Permit TCP 1883 from 192.168.20.0/24 to 192.168.10.20 — the configured port, from the controller's subnet — and retest. A healthy connect is a three-packet handshake at the route's round-trip time, about 3 ms here, so any connect not complete within 1 s still belongs to stage 2. Only once it completes in well under a second do you touch publish logic. Had the connect instead been refused instantly, you would have skipped the firewall and fixed the listener.
Where the MQTT client should live #
No special module is required — a controller with an Ethernet port and a client implementation speaks MQTT. Pick the placement by where the protocol work and its long-term maintenance should sit:
- In the controller. Rockwell publishes MQTT Client AOIs for publishing and subscribing in its Common Application Libraries, available through its Product Compatibility and Download Center. On a CompactLogix 5380 this keeps the client inside the project, and you own the socket logic, the testing and the documentation for whoever maintains it after you. Verify controller and firmware support in the library documentation for the installed version, and before designing around a rumored native MQTT setting in a specific firmware release, confirm it in the controller documentation — version-specific protocol features are sometimes confused with another protocol such as OPC UA.
- On a bridge. Node-RED reads the controller's tags over EtherNet/IP and publishes them itself; the PLC project stays untouched. The data path is the same one described in Bridging OPC UA PLC data to MQTT with an edge PC. When the bridge needs its own cabinet-mounted host, a fanless industrial mini PC is the usual fit.
- On a gateway or HMI. A device with a built-in MQTT client is the fastest route to a first message and adds one more box to maintain and secure. The trade-offs between publishing from the controller directly and going through a gateway are compared in PLC MQTT direct publishing versus an IoT gateway.
Decision: a basic transfer of a handful of tags fits the AOI or the bridge; buffering, many topics, TLS termination or command paths back into the PLC justify a dedicated gateway or edge host.
The fix, in order #
- Listener. Connect to the configured port from the broker's own subnet. Fails: define the listener on the plant-facing interface and match authentication. Decision: the broker answers locally before anything else is tested.
- Path. Connect from the controller's subnet to the configured port. Silent timeout: permit that port for that source subnet. Instant refusal: back to the listener. Decision: the connect completes in well under a second on the plant LAN.
- Publish. Subscribe on
#with a test client, trigger the publish, watch. Message appears: fix the real subscriber's topic filter. Nothing: fix the trigger, status or topic. Decision: the message is visible on the wildcard subscription before the production subscriber is touched.
From the moment a test publish lands on a wildcard subscription, what remains is ordinary pipeline work — topics, payload shape and publish rate.
Questions asked
Do I need a special module to publish MQTT from a CompactLogix controller?
No. Put the client in the controller using the vendor's MQTT Client AOIs from the Common Application Libraries, run a Node-RED bridge that reads tags over EtherNet/IP, or use a gateway or HMI with a built-in MQTT client. For a few tags the AOI or bridge is enough; budget the AOI route's integration and validation hours against a gateway's setup time, and document whichever you choose so the design survives staff changes.
Why does the broker work from my PC but time out from the PLC?
The usual cause is the listener, not the network. Since Mosquitto 2.0, a configuration with no listener entry accepts local connections only, so a test on the broker machine succeeds while remote clients time out. Add a listener bound to the plant-facing interface, then restart the broker; an edited configuration that was never restarted still listens locally. After that, verify the path from the controller's own subnet.
How do I get positive proof the broker accepted a publish?
Publish at QoS 1 for the test. At QoS 0 the client sends the message and never asks whether it arrived, so a drop looks identical to a success. At QoS 1 the broker answers with a PUBACK, and that acknowledgment in your client's status or debug output is positive proof the broker took the message before you blame or clear the subscriber.
Does a TLS listener on port 8883 change the connect test?
It changes the signature, not the method. A TCP connect to 8883 succeeds even though no MQTT session will, because TLS is negotiated after the connection opens; a plaintext CONNECT sent to a TLS listener is rejected at the first bytes. So a completing TCP connect proves only reachability; confirm the client uses the same transport security the listener expects before reading the result.
Why does my client connect and then drop off the broker a few minutes later?
Keepalive. The client sends keepalive pings at the configured interval, and the MQTT specification requires the broker to disconnect any client from which it receives nothing for one and a half times that interval. With a 60 s keepalive, silence past 90 s ends the session. Publish on a period shorter than the keepalive, or fix the ping logic so it actually runs.