I have been using the following function (posted elsewhere in the forum) without any problems. However at one particular site where my application is installed, when the application is started after power up, it will hang at the "wait for" statement. The log will show "Trying to Connect" and the application get "hung" at the "wait for" statement making it unresponsive. It's not a network issue because I checked connectivity and even if it were, the program should not get hung up. Just wondering how that can happen. Is there a timeout built into the "wait for"?
Sub ConnectAndReconnect Do While working If mqtt.IsInitialized Then mqtt.Close mqtt.Initialize("mqtt", server, clientID) Dim mo As MqttConnectOptions mo.Initialize(user, password) Log("Trying to connect") mqtt.Connect2(mo) Wait For mqtt_Connected (Success As Boolean) If Success Then Log("Mqtt connected") mqtt.Subscribe(mytopic,0) Do While working And mqtt.Connected mqtt.Publish2("ping", Array As Byte(0), 1, False) 'change the ping topic as needed Sleep(30000) Loop Log("Disconnected") Else Log("Error connecting.") End If Sleep(30000) Loop End Sub