|Error handling when no PINGRESP received [message #1721105]
||Sat, 23 January 2016 21:37
| Will Luke
Registered: January 2016
I'm new to MQTT and loving it so far. But I'm trying to find out how to handle timeouts, particularly when a PINGRESP hasn't been received by a client.
I'm checking for a valid internet connection when the initial connection fails and essentially waiting until it becomes alive again. But if the remote broker fails or becomes unresponsive, how can I restart the connection from the beginning? Currently, the forever loop just waits to receive the PINGRESP (and waits forever)
I'm tinkering in Python at the mo. Thoughts welcome
# We should probably log this successful connection via mtqq in g, in a text file
# mqttc.publish("g/lamp", "ON")
rc = 0
while rc == 0:
rc = mqttc.loop_forever(60,60,retry_first_connection=True)
print("rc: " + str(rc))
# Can't reach the server. We should check to see if the internet can be reached at all with a variety of pings
# Also, colour the light red to indicate connection trouble
print "Connection trouble. Let's check to see if we can ping anything"
if have_internet() is True:
print "Internet connection is working. We'll sleep for 10 secs"
Powered by FUDForum
. Page generated in 0.01993 seconds