MQTT AnyCloud Connection Issue - "Network is unreachable"

Hello everyone,

I have a problem with the MQTT AnyCloud configuration of my PFC300. Here’s my situation:

Current Configuration:

  • Wago PFC300 PLC : IP 192.168.a.x (local network)

  • MQTT Server : IP 192.168.b.x (different local network)

  • MQTT Broker : Local Mosquitto on port 1883

Issue Encountered:

  • Connection 1 : Is Active: true

  • Cloud connection : disconnected

  • Diagnosis : “The connection was lost” + “Network is unreachable”

Tests Performed:

  • MQTT Server : Working perfectly (Node.js connections OK)

  • Port 1883 : Accessible from the server

  • PLC : Cannot reach the MQTT server

MQTT AnyCloud Configuration :
Hostname: 192.168.a.x (local router IP)
Port: 1883
Client ID: wago_001
Clean Session: Enabled

Are the PLC and the broker on the same network ?
Can you ping broker from the PLC ?
What is the logs in the PLC ? (check /var/log/messages and look for DataAgent messages)
What is the broker ?

I’m connected to a VPN, and I can ping the PLC from my laptop. I can ping the rooter also. So in the MQTT anycloud connection configuration I entered the rooter ip in the hostname because the rooter have access to PLC and to my laptop which have different networks. So no, they don’t have the same networks but the rooter is like a gateway I think.

How can I ping the broker from the PLC ?

My broker is Mosquitto which turned on my server (my laptop ip).

Here are the logs :

Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Starting with logging level 127][DataAgent.cpp L:476]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Application version: 1.16][DataAgent.cpp L:477]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Command line arguments: -d][DataAgent.cpp L:379]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Detected plcRuntime = CodesysV3][Common/FileSystem.cpp L:54]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Warning][Failed reading CmpApp.Application.1 from /home/codesys/CODESYSControl.cfg][WagoProtocol/FwUpdateConfigTool.cpp L:286]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure LoggingLevel = Default][Configuration/ConfigurationManager.cpp L:848]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.Enabled = true][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.CloudType = AnyMQTT][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.Compression = None][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.AuthenticationMethod = DeviceKey][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.MessagingProtocol = NativeMQTT][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.CacheMode = RAM][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.ProxyType = None][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.HttpProxyPort = 8080][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.SendDeviceInfo = true][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.SendDeviceStatus = true][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.StandardCommandsEnabled = true][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.TelemetryStopped = false][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.Port = 1883][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.CleanSession = true][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.UseTLS = false][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.LastWillEnabled = false][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.CaFile = /etc/ssl/certs/ca-certificates.crt][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.LastWillQoS = 0][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.LastWillRetain = false][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.Host = ***][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.ClientId = ***][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection1.KeepAliveInterval = 120][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Configure Connection2.Enabled = false][Configuration/ConfigurationManager.cpp L:811]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Initialized][AgentControl/OperationStatusObserver.cpp L:43]
Nov  8 04:06:06 PFC300-69594F DataAgent[570]: Last message '[Info][Initialized][' repeated 1 times, suppressed by syslog-ng on PFC300-69594F.lan
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][UDP 127.0.0.1:14118 setsockopt SO_RCVBUF: requested 2097152, got 425984][Util/IPC/IpcUdp.cpp L:94]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Connection1: Initialized][AgentControl/AgentBusReaderUdp.cpp L:35]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][UDP 127.0.0.1:14119 setsockopt SO_SNDBUF: requested 2097152, got 425984][Util/IPC/IpcUdp.cpp L:170]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][UDP 127.0.0.1:14120 setsockopt SO_SNDBUF: requested 2097152, got 425984][Util/IPC/IpcUdp.cpp L:170]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Connection1: Mosquitto Library version:1.6.7][Connection/TransmitterMosquitto.cpp L:183]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Connection1: Initialized][NativeMQTT/TransmitterNativeMqtt.cpp L:23]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Connection1: Initialized][NativeMQTT/DatagramsManagerNativeMqtt.cpp L:27]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Connection1: Initialized][NativeMQTT/CustomDataManager.cpp L:46]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Running][AgentControl/AgentBusReaderBase.cpp L:21]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Err][Connection1: mosquitto_connect_async failed. Error 14: Network is unreachable][Connection/TransmitterMosquitto.cpp L:496]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Err][Connection1: mosquitto_connect_async failed. A System call returned an error: Network is unreachable][Connection/TransmitterMosquitto.cpp L:503]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Warning][Connection1: No connection to broker could be established.][Connection/TransmitterMosquitto.cpp L:506]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Connection1: Running][Connection/TransmitterMosquitto.cpp L:161]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Connection1: Running][NativeMQTT/CustomDataManager.cpp L:53]
Nov  8 04:06:06 PFC300-69594F DataAgent[990]: [Info][Connection1: Running][NativeMQTT/DatagramsManagerNativeMqtt.cpp L:34]

Could you make a basic drawing of your network with IP addresses / subnet mask and gateway ?

You can connect to the PLC using SSH (software like PuTTy) and use the command ping

Hi,

Indeed, I can’t ping my ip (localhost) from the PLC. But this is because I’m connected to a VPN. I think that I should put my broker to a VPS. Because if I turn off my pc, the broker will not receive datas anymore

If I download MQTT Broker into the Wago with SSH access, can it be a solution to my problem ? Thus, I can publish data from codesys directly with “localhost” for hostname into the MQTT Client.

Is the VPN client installed on the PFC? (does the PFC know about the route to 192.168.b.x?)

If not, is it a site-to-site VPN between the “PFC”-router and your office? If so, you need to use 192.168.b.x in the MQTT AnyClient configuration and handle the NAT/ routing on the “PFC”-router.

Configuring the MQTT AnyClient with the router IP won’t work unless you have NAT’ing on it or the MQTT broker is actually running on the router.

It’s hard to understand without a schematic of your network, where the broker is installed, etc…

Exactly, it is a site-to-site VPN between the PFC et my office.
Oh okay, I understand I was thinking about that also, thank you

Here is a schema (fake values)

NB : My Goal is to publish data in real time on the broker with codesys. And retrieve them with node js (a backend server)
NB2: The ping works only in one way from the pc to the devices

Hello,
So your Broker is your PC.
Your PC is remotely connected to the PLC via a VPN.
The PC can ping the PLC and the PLC can ping the PC.
Is the PLC and PC on the same time ? can you check with the WBM that the PLC time and the PC time are synchro ?
Have you done the NTP settings in the PLC to make sure the time is always updated ?

In the PLC when you connect via putty, you can test the connection using:

killall dataagent

to “kill” all cloud connections.
Then to restart is in your current session:

dataagent

If you shutdown the ssh link the dataagent will also be killed.
But by doing this you can retry to connect when doing test without having to reboot the PFC.
(Bonus the log are colored).

Hello,

The PLC cannot ping the PC but the PC can ping the PLC. I didn’t update the time in the PLC so they are not synchro indeed. How can I do that please ?

I think I will move the broker to a VPS because if I put it in the PC, when I will shutdown the PC I will lost the connection.

Of course, the computer is the last place where you want to put the broker.
And your computer firewall doesn’t accept inbound connection, or at least doesn’t answer to ICMP request (ping).
Depending on which services will publish/subscribe to the MQTT data produced by the PLC, you could afford to install the broker within the PLC, using Docker.

https://hub.docker.com/_/eclipse-mosquitto

Thank you ! I will do that but last question, if the VPS cannot access to the PLC (there are in different networks) how can I catch the values sent to the broker ?

Mqtt Client MyPC (CodeSys) publishMqtt Broker PLC ← follow VPS Mqtt Client

If the broker is public accessible there shouldn’t be a problem. Try setting up a free instance at HiveMQ for test purposes and god on from there

Thank you I’m trying it now, but do you know why when I want to setup the time of my PLC with NTP Client it show me : ntp.client.updatetime: config_sntp: 8 No functioning time server found

My PLC is configured with different date & time than my PC

I found that my PLC have not access to the internet ! It can’t ping 8.8.8.8

Make sure DNS and gateway are set properly

Hello,

DNS & Gateway on the network configuration are set to the router ip (192.168.x.1).
The Wago controller is connected to the switch by rj45 so it should have internet access. I’m lost