Categories
Uncategorized

Arduino/ESP32: Disabling the task watchdog

Recently I’ve been playing around with ESP32’s multicore functionality and task pinning to specific cores.

I was using AutoConnect to support WiFi connection without storing credentials in the code and provide OTA updates via the web UI.

This was for a project that was going to control some CPU 4-pin PWM fans that are in my server closet, to cool the air inside. For that I wanted to split the logic in two tasks.

One task to handle API’s, sensor reading, updates, WiFi, etc. and one task to handle the interrupt and PWM control of the fans.

All was good, tasks were created, but when running the code, if I get the ESP32 in the mode where you need to connect to it to tell it to connect to your WiFi network, it started exhibiting a strange behavior – it started to reset the controller every few seconds and I couldn’t make the connection work.

That was annoying time, having to unmount the controller from it’s place and connect it to USB to flash a new firmware.

After doing the above I noticed that the error was coming from the watchdog:

Task watchdog got triggered. The following tasks did not feed the watchdog in time:
 - IDLE (CPU 1)
Tasks currently running:
CPU 0: ManageTask
CPU 1: ControllerTask

Looking around, it seems that this is triggered by the ESP32’s Task Watchdog, which makes sure the tasks get their turn to execute on the CPU.

And it also seemed that AutoConnect wasn’t very flexible when working in a Task context, compared to running outside of one, directly with all the other code and functionality.

Digging around a bit and trying different things, it seems that the easiest way to get oneself out of this situation is to just disable the watchdog and hope that things get executed in time 🙂 The task is not mission-critical, so it’s fine to wait more time for it to complete what it’s doing.

To disable the watchdog, you need to do two things:

First is to Include the esp_task_wdt.h header. To do that, add #include <esp_task_wdt.h> to your include section

Second, make the watchdog not reset the controller and wait more time. To do this, you need to add esp_task_wdt_init(30, false); at the start of your Task code.

void manage_core_task(void *pv_parameters) {
    esp_task_wdt_init(30, false);
    .... rest of the code ...
}

This will set the watchdog timeout to 30 SECONDS and disable the controller reset if it’s triggered.

If you want to have the controller still reset after the watchdog is triggered, change the second parameter of the function call from false to true.

By Biser Perchinkov

Look, a coder!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s