I'm using an RFID to open a door.
I'm also using MQTT to open the door and monitor its status.
The main code is like the one bellow:
Code: Select all
while True:
try:
client.check_msg()
except OSError as e:
restart_and_reconnect()
# Bellow there is another code to monitor local RFID tag and open the door
# Code here
Code: Select all
def restart_and_reconnect():
print('Failed to connect to MQTT broker. Reconnecting...')
time.sleep(10)
machine.reset()
Last night there was no power and my router was offline. That kept me outside until power restore.
Is there a way to reconnect without send a machine.reset()?