1

I am trying to connect a Wago PFC200 controller to the mosquitto broker I have running on my laptop using the MQTT_Client library by Stefan Rossmann Engineering Solutions.

I get "Connecting to TCP-Server Timed out" error and I'm having trouble figuring out how to troubleshoot it. Before running out of ideas I've tried forcing a bigger value of timeout during runtime, changing the port I'm trying to connect to or the IP — switching to HiveMQ's public MQTT broker, a broker running on my phone and on another laptop. Not sure if that's relevant, but I'm working in e!cockpit.

The socket is created successfully and then the error occurs because xResult := SysSockConnect(diSocket, ADR(sockAddr), SIZEOF(sockAddr)); does not change to True — why exactly may that be?

IF (sockAddr.sin_addr = 0) THEN
        sockAddr.sin_family := SOCKET_AF_INET; 
        IF (right(i_sBrokerAddress,1) = '0' OR right(i_sBrokerAddress,1) = '1' OR right(i_sBrokerAddress,1) = '2' OR right(i_sBrokerAddress,1) = '3' OR right(i_sBrokerAddress,1) = '4'
            OR right(i_sBrokerAddress,1) = '5' OR right(i_sBrokerAddress,1) = '6' OR right(i_sBrokerAddress,1) = '7' OR right(i_sBrokerAddress,1) = '8' OR right(i_sBrokerAddress,1) = '9') THEN
            sockAddr.sin_addr := SysSockInetAddr(i_sBrokerAddress); 
        ELSE
            sockAddr.sin_addr := SysSockGetHostByName(i_sBrokerAddress);
            
            
        END_IF
    END_IF
     
    sockAddr.sin_port :=  SysSockHtons(i_uiPort);
    wTimeOutValue:=1000;
    xResult := SysSockConnect(diSocket, ADR(sockAddr), SIZEOF(sockAddr));
    q_sDiagMsg:='Connect to TCP-Server';
    IF (xResult) THEN
        q_udiState:=15; 
    END_IF
    IF (TON_TimeOut.Q) THEN
        q_udiState:=90; 
        q_xError := TRUE;
        q_sDiagMsg:='Connecting to TCP-Server Timed out';
    END_IF
sashilio
  • 11
  • 1

0 Answers0