Struggling with combination of webrepl and watchdog

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
RobertPrins
Posts: 2
Joined: Wed Jul 07, 2021 9:53 am

Struggling with combination of webrepl and watchdog

Post by RobertPrins » Wed Nov 24, 2021 3:09 pm

I am building a controlled access system for my club's clubhouse. Each of the individual doors is equipped with an electric lock and an iButton reader, which will be controlled by an esp32 board(MH-ET Live) programmed in micropython. Since the electronics will be housed in hard to access places, webrepl was the way to go to enable remote diagnostics and software maintenance.

The start was with 3 doors(out of the 12 doors in total). A pattern soon resulted. For each door the software would work like a charm for a few weeks and then would suddenly stop. Webrepl was also not responding anymore. I used the python try plus error logging, but no exception was caught and the software kept stopping operation. Then I activated the watchdog timer: in my 250 millisecond event-loop I feed the watchdog and after 10 seconds of not being fed the watchdog resets and reboots the system. The locks have now delivered uninterrupted service for 6 months. Good dog!

Time to scale up to 12 doors, with a slightly modified python program. Connecting with webrepl, stopping the python program with Ctrl-c, uploading the new... Shit the watchdog has not been fed in time. I thought the program had stopped completely, but the watchdog remains active and cannot be stopped. The node will restart and I will have to reconnect with webrepl, stop the program, upload the new version, but will never succeed within 10 seconds, so the watchdog will bite me again and I am stuck in an everlasting loop.

The watchdog cannot be turned off once it is activated. Rebooting the system does turn off the watchdog though. I have now made a new version of the program in which the watchdog is no longer turned on in the boot code, but it is later toggled ON in response to an mqtt message. When toggled to ON, the event handler will create the watchdog, when toggled to OFF the same event handler will reboot the system. So now, when maintenance is required, I first toggle off the watchdog and then connect with webrepl, stop the python program with Ctrl-c and do the necessary maintenance, restart the system and lastly send an mqtt message to toggle on the watchdog. I am confident this will keep working over time, but when reality kicks me in the butt again, I will update. Robert.

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: Struggling with combination of webrepl and watchdog

Post by karfas » Wed Nov 24, 2021 5:20 pm

You might be interested in the discussion in https://github.com/micropython/micropython/pull/6631 .
The solution there was to reinitialize the watchdog with a longer timeout during the upgrade process.
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

RobertPrins
Posts: 2
Joined: Wed Jul 07, 2021 9:53 am

Re: Struggling with combination of webrepl and watchdog

Post by RobertPrins » Thu Nov 25, 2021 2:46 pm

Well, I am learning (micro)python by solving an actual problem with it and I use any problem I encounter to deepen my understanding. So yes point taken, but the extra effort I put in did not go to waste. Besides there is no de-init method in the micropython documentation, neither is mentioned the possibility to reinitialize an already active watchdog with a larger period. Just liked to share my solution, which solves the problem within the scope of the current documentation.

Micropython plus webrepl are awesome tools for IOT projects. I am an old hand in this field and used to develop with in circuit emulation and/or jtag in languages like C and assembler. I am stunned by the power of micropython, by the opportunity it provides to test everything directly inside the hardware target.

Post Reply