Troubleshooting
Why the TwinCAT Analytics logger stays Disconnected to MQTT
Short answer
The Data Logger's MQTT client runs on the TwinCAT runtime host, so the loopback destination in its Parameter (Init) tab points at that machine, not the engineering workstation where the Target Browser and test tools succeed. The reported fix was an explicit Mosquitto listener on port 1883 in mosquitto.conf, opened on the interface the runtime reaches. Match the destination to the host that runs the logger, then confirm PlcStream1 in the Online tab.

On this page
A TwinCAT 3 Analytics logger stream that stays Disconnected while the Target Browser shows connected is an addressing fault before it is a logger fault. The Data Logger's MQTT client executes on the TwinCAT runtime host, so the loopback destination entered in its Parameter (Init) tab names that machine, not the engineering workstation where the other clients succeed. The reported correction was an explicit listener 1883 in mosquitto.conf, so the broker serves the interface the runtime actually reaches. Trace the three clients separately, fix the endpoint, and the stream appears.
Where the logger's client actually runs #
The TwinCAT 3 Analytics Logger either acts as an MQTT client and transmits each stream to a message broker on a regular basis — its MQTT mode — or stores the data instead. You configure it inside the TwinCAT project, but the configuration executes with the runtime on the target, the machine covered in running TwinCAT XAR on a third-party industrial PC, not where the project happens to be open.
The address 127.0.0.1 never leaves the computer that originated it. With that destination, the logger knocks on the runtime host's own loopback interface. If the broker runs on that host and listens there, the connection works; if the broker runs anywhere else, nothing answers and PlcStream1 sits at Disconnected in the Online tab no matter how healthy the broker looks from your desk.
Why the Target Browser and a test tool still connect #
The Target Browser and the third-party publish/subscribe tool are independent MQTT clients. Each has its own originating machine, destination and credentials, so each success proves exactly one path.
| Client | Runs on | Destination it uses | What success proves |
|---|---|---|---|
| Data Logger stream PlcStream1 | TwinCAT runtime host | the Parameter (Init) address | the runtime host's path only |
| Target Browser | engineering workstation | its own connection page | the workstation's path only |
| Third-party test tool | wherever you launched it | the address you typed | that single test path |
A green Target Browser connection is therefore not a broker-wide health indication; it says the workstation can reach whatever endpoint that page names.
The Mosquitto listener correction #
Mosquitto's current default binds only to the local machine, a deliberate secure posture, so a broker that passes your local tests can still refuse the logger. The reported fix adds two lines to mosquitto.conf:
listener 1883opens an explicit listener on that port, on all interfaces of the broker host; a listener line can also carry one bind address to narrow it.allow_anonymous trueadmits clients without credentials, a separate matter from reachability.
Keep anonymous access confined to an isolated test bench or a bounded diagnostic; on a production network, require client credentials and bind the listener to the single interface the runtime host uses. Reload the broker with the procedure your service manager supports, read the startup log for bind errors, and confirm the socket now accepts connections on the intended interface.
Trace the failing path in order #
- Name the three machines on paper: the TwinCAT runtime host, the broker host and the engineering host. If two of them are the same box, say so.
- Read the destination in the Data Logger's Parameter (Init) tab. A loopback destination means the runtime's own machine; when the broker lives elsewhere, this field is the fault.
- On the broker host, inspect the active listening sockets and note the bound address and port. A loopback-bound socket cannot accept traffic that arrives through a network interface.
- From the runtime host, run a TCP connect test to the broker's address and port; a test from the workstation proves a different path whenever the runtime is remote. While there, confirm link state, address assignment and firewall rules on the runtime's NIC, the checks collected in TwinCAT license class and NIC checks on a third-party PC.
- Correlate one connection attempt with the broker log or a packet capture, then map the observation to its failure boundary:
- No packets arrive at the broker: wrong destination, missing route, firewall, or a logger configuration that was never activated on the target.
- Connection refused: no listener at that address and port, or an active rejection. Compare the socket's bound address with the logger's destination.
- Connection accepted, then dropped during the MQTT handshake: credentials, client identifier or protocol settings, the class of failure in why Mosquitto 2.0 rejects a Telegraf MQTT output.
- Connected but the stream never shows in the Target Browser: publish permission on the broker, or the browser pointed at a different endpoint.
- Re-open the Online tab, confirm PlcStream1 no longer reads Disconnected, and confirm the stream now appears nested under the Target Browser connection.
Worked example: proving the path with the addresses #
Take a runtime host at 192.168.1.20 with mask 255.255.255.0 and a broker host at 192.168.1.50. The runtime's network portion is 192.168.1.20 AND 255.255.255.0 = 192.168.1.0; the broker's is 192.168.1.50 AND 255.255.255.0 = 192.168.1.0. The results match, so packets cross directly from one NIC to the other with no router involved, and a refused connection there means no listener on that endpoint, not a routing fault. If the runtime instead sat at 10.0.0.20 with mask 255.0.0.0, its network portion would be 10.0.0.0, which does not match, so the traffic would hand off to the default gateway and every firewall along that hop joins the diagnosis before you blame the broker.
The decision for each case #
- Broker on the runtime host: keep the loopback destination in the Parameter (Init) tab and make sure the broker's listener accepts loopback connections; an explicit listener without a bind address covers loopback and every other interface at once.
- Broker on another host: replace the destination with that host's reachable address, as in the worked example, and open the explicit listener on the broker. Opening a listener never makes a remote machine's loopback reachable, so both ends must change.
- Logger connected but no stream visible: point the Target Browser at the same broker endpoint first, then check broker publish rights and stream discovery before adjusting any retry setting.
Questions asked
Does Mosquitto listen on every network interface by default?
No, not in current releases. Since the 2.0 series an unconfigured broker serves only its own machine, a deliberate secure default; releases before that listened on every interface, which is why older guides claim the opposite. An explicit listener line opens the chosen port on all interfaces of the broker host, and adding a bind address to that line narrows it to one.
Is anonymous client access safe for a plant MQTT broker?
Only on an isolated test bench or during a bounded diagnostic. It admits any client that reaches the port, with no credentials, free to publish and subscribe. For production, keep the explicit listener but require client credentials and bind it to the single interface the runtime host uses, so the broker exposes one door instead of every door.
Which MQTT quality-of-service level suits a logged data stream?
MQTT defines three levels: 0 delivers at most once, 1 delivers at least once but can duplicate, and 2 delivers exactly once with the most broker handshaking. For stream samples bound for a historian, level 1 with duplicate handling at the receiving end is the usual engineering choice; level 0 suits live dashboards where the next sample supersedes a lost one.
Will a longer connect timeout fix a stream that shows Disconnected?
No. A refused TCP connection comes back immediately, so the logger is not waiting on a slow network; a wrong destination or a missing listener fails at any timeout. Fix the destination address and the broker listener first, and read retry or timeout values from the installed logger configuration only afterwards, if repeated attempts need pacing.


