I'm counting pulses from an electricity meter using an ESP32 DEVKIT and an ISR to increment a variable.
I'm seeing errors like this:
E (17121869) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (17121869) task_wdt: - IDLE0 (CPU 0)
E (17121869) task_wdt: Tasks currently running:
E (17121869) task_wdt: CPU 0: wifi
E (17121869) task_wdt: CPU 1: loopTask
E (17121869) task_wdt: Aborting.
I'm wondering if my loop() is placing an unnecessary demand on the ESP32. Basically it repeatedly checks a set of conditions that will not change too often - so there would be room to allow the ESP to do some housekeeping, eg by adding a short delay() between loops.
void loop() {
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
//pollInput(); //alternative for testing without interrupt
PulseState = digitalRead(intPin); //reflect input pulse to LED
digitalWrite(LED_Pulse, (PulseState + 1) % 2); //because input active low
/* *** members of timeinfo structure access as eg timeinfo.tm_yday for day number of year
int tm_sec seconds [0,61]; int tm_min minutes [0,59]; int tm_hour hour [0,23]; int tm_mday day of month [1,31]
int tm_mon month of year [0,11]; int tm_year years since 1900; int tm_wday day of week [0,6] (Sunday = 0)
int tm_yday day of year [0,365]; int tm_isdst daylight savings flag
*/
if (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time");
return;
}
if (!fileNameSet ) {
// if its not yet been set - maybe reset of time failed?
newMonth(); //no file exists as yet so create one and
currMonth = timeinfo.tm_mon; //update current month
}
checkPeriod(); //record current, previous, max values of watts
if (timeinfo.tm_mday != currDay) {
//start of new day
newDay(); //save day data to file
currDay = timeinfo.tm_mday; //update current day
}
if (timeinfo.tm_mon != currMonth) {
//start of new month
newMonth();
currMonth = timeinfo.tm_mon; //update current month
}
buildDate();
if ((millis() - lastTime) > timerDelay) {
// Send Events to the Web Server with the Sensor Readings
events.send("ping",NULL,millis());
events.send(String(myDate).c_str(),"time",millis());
events.send(String(dTotalkWh).c_str(),"dtotal",millis());
events.send(String(yTotalkWh).c_str(),"ytotal",millis());
events.send(String(pWatts).c_str(),"pwatts",millis());
events.send(String(mWatts).c_str(),"mwatts",millis());
events.send(String(cWatts).c_str(),"cwatts",millis());
lastTime = millis();
}
} //end of loop