Not sure which Category to include this in so starting here.
Hi Folks
Hardware - Wemos D1 Mini ESP32
Arduino IDE 2.3.3
I'm having trouble getting the Watchdog timer provided by the esp_task_wdt.h library to execute a reboot on trigger if any or all of the the following libraries are included (whether referenced or not) in the code.
#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <PubSubClient.h>
To put it into context I have several battery powered ESP32's with Capacitive Soil Moisture Sensors. Monitoring the sensor readings twice daily is quite sufficient so I'm putting the D1 Mini into Deep Sleep after each reading to preserve battery life.
I have found that sometimes on awakening the device files to either connect to the router or the MQTT server and just hangs until such time as the battery is depleted, Hence the attempt to use the watchdog timer to reboot.
In my own code which I won't include here for the time being I found the watchdog timer did trigger but failed to reboot.
I therefore found an example sketch which worked with the same hardware configuration, eliminating the possibility of the wrong GPIO's in use having any possible relevance and which repeatedly rebooted the processor.
After adding in my 4 libraries the sketch acted in precisely the same manner as my own code. Removal of each library individually had no effect on the result until all 4 had been removed.
This is the code for the test example
#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <PubSubClient.h>
#include <esp_sleep.h>
#include <esp_task_wdt.h>
//3 seconds WDT
#define WDT_TIMEOUT 3000
//if 1 core doesn't work, try with 2
#define CONFIG_FREERTOS_NUMBER_OF_CORES 2
#define CONFIG_ESP_SYSTEM_PANIC CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
esp_task_wdt_config_t twdt_config = {
.timeout_ms = WDT_TIMEOUT,
// .idle_core_mask = (1 << CONFIG_FREERTOS_NUMBER_OF_CORES) - 1, // Bitmask of all cores
.trigger_panic = true,
};
void setup() {
Serial.begin(115200);
Serial.println("Configuring WDT...");
esp_task_wdt_deinit(); //wdt is enabled by default, so we need to deinit it first
esp_task_wdt_init(&twdt_config); //enable panic so ESP32 restarts
esp_task_wdt_add(NULL); //add current thread to WDT watch
}
int i = 0;
int last = millis();
void loop() {
// resetting WDT every 2s, 5 times only
if (millis() - last >= 2000 && i < 5) {
Serial.println("Resetting WDT...");
esp_task_wdt_reset();
delay(1000);
last = millis();
i++;
if (i == 5) {
Serial.println("Stopping WDT reset. CPU should reboot in 3s");
}
}
}
I would include the console output for the sketch with and without the the libraries included but My Arduino IDE does not appear to allow we to select more than a few lines at a time of the bottom pane. In that pane neither right click of the mouse nor Ctrl-A have any effect nor do normal text selection techniques work properly to allow text to be copied from it.
I hope someone my be able to help with the Watchdog issue.