I have several ESP32s that run Peter Hinch's excellent mqtt_as.py library and are connected to temperature sensors. I've set up WDT to reboot them if they get into an odd state, but just occasionally, maybe once every month or two, they manage to get into a state where they no longer send updates but the WDT doesn't reboot them either so I end up having to go out and physically press the reset button on them. Rather annoying.
Instead of attempting to figure out something that happens so rarely, I figured I'd just schedule a machine.reset() every week. I'm testing this on my spare FeatherS2 (the other devices that are in active use are Adafruit's HUZZAH32s) and the code in question at the bottom of main.py looks like this:
Code: Select all
[...snipped...]
client = MQTTClient(config)
async def weekly_reboot():
while True:
await uasyncio.sleep(604800) # 1 week in seconds
logger.log('Weekly reboot!')
reset()
try:
uasyncio.create_task(weekly_reboot())
uasyncio.run(main(client))
uasyncio.run(weekly_reboot())
finally: # Prevent LmacRxBlk:1 errors.
client.close()
uasyncio.new_event_loop()
Am I doing something silly, or missing something, or is there a maximum limit that uasyncio.sleep() will take?
Many thanks!