Periodic Reset of ESP32

I have this IoT project where I post a pressure value once every 30sec to the ThingSpeak cloud using a ESP32 Feather from Adafruit. All well. And this module runs of a mains powered 5V and so issues of saving battery etc.

Occasionally the ESP32 locks up and needs a manual reset. I know one way out of this is to use the timer based deep sleep mode. But I need to keep the code alive to average the pressure data over time.

So I was wondering if there is anyway to invoke the RESET function of the ESP32 once every 10 minutes inside the loop()?

This way in a worst case scenario I will loose about 10 minutes of data in case the ESP32 hangs but the advantage is I can leave it unattended and yet be sure it wont be locked up for days on end.

If you have uploaded a script with debug enable and commented out all the serial prints to stop screen scrolling, the ESP should print out an error which could be used to troubleshoot the issue.

Yes. I have ESP32 watchdog code here you can adapt it to your needs:

int LIDAR_Watchdog_Counter = 1; //<<<< a globablly declared variable

void fResetWatchDogVariables ( void *pvParameters )
{
  for ( ;; )
  {
    xEventGroupWaitBits (eg1, evtResetWatchDogVariables, pdTRUE, pdTRUE, portMAX_DELAY) ;
    xSemaphoreTake ( sema_LIDAR_Watchdog_Counter, xSemaphoreTicksToWait );
    LIDAR_Watchdog_Counter = 1;
    xSemaphoreGive ( sema_LIDAR_Watchdog_Counter );
    xSemaphoreTake ( sema_LIDAR_OK, xSemaphoreTicksToWait );
    bLIDAR_OK = true;
    xSemaphoreGive ( sema_LIDAR_OK );
  }
  vTaskDelete ( NULL );
} // void fResetWatchDogVariables ( void *pvParameters )
void fLIDAR_Watchdog_Inc( void *pvParameters )
{
  for (;;)
  {
    xEventGroupWaitBits (eg, evtLIDAR_Watchdog_Inc, pdTRUE, pdTRUE, portMAX_DELAY );
    xSemaphoreTake ( sema_LIDAR_Watchdog_Counter, xSemaphoreTicksToWait );
    LIDAR_Watchdog_Counter = LIDAR_Watchdog_Counter << 1;
    if ( LIDAR_Watchdog_Counter < 0 )
    {
      ESP.restart();
    }
    xSemaphoreGive ( sema_LIDAR_Watchdog_Counter );
  }
  vTaskDelete( NULL );
}
//////////////////////////////////////////////////////////////////////////////////////////
void fLIDAR_Watchdog( void *pvParameters )
{
  for (;;)
  {
    xEventGroupWaitBits (eg, evtLIDAR_Watchdog, pdTRUE, pdTRUE, portMAX_DELAY );
    Serial.println ( "fLIDAR_Watchdog" );
    xEventGroupSetBits( eg, evtfLIDAR_Power_Off ); // turn power to the LIDAR unit off.
    xSemaphoreTake ( sema_LIDAR_OK, xSemaphoreTicksToWait );
    xHandle_ReceiveSerial_LIDAR = NULL;
    bLIDAR_OK = false; // begin timer count to turn LIDAR unit on
    xSemaphoreGive ( sema_LIDAR_OK );
  }
  vTaskDelete( NULL );
} //void fLIDAR_Watchdog( void *pvParameters )

For the ESP32 use ESP.restart();, the ESP8266 uses a different reset command.