ESP32 - How to disable watchdog timer for HTTP server?

Attempt 1

#include <esp_task_wdt.h>

After the baud rate is set, in void setup, I tried putting in esp_task_wdt_init(30, false);

The HTTP server "can't be found." So it never even starts. I also tried putting the esp_task_wdt_init(30, false); after the server begins. Same failing result.

Attempt 2

#include <soc/rtc_wdt.h>

Same thing, right after baud rate is set in void setup:

rtc_wdt_protect_off();
rtc_wdt_disable();

This time, the GUI functions just like before (as if the watchdog timer/interrupt is not actually disabled). The HTTP server runs normally, but "crashes", page times out. I also tried putting those two functions (or whatever they are called after server.begin() in void loop. The same results, "ERR_CONNECTION_TIMED_OUT" on web server and here in the serial monitor:

E (169245) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (169245) task_wdt: - async_tcp (CPU 0/1)
E (169245) task_wdt: Tasks currently running:
E (169245) task_wdt: CPU 0: IDLE0
E (169245) task_wdt: CPU 1: IDLE1
E (169245) task_wdt: Aborting.
abort() was called at PC 0x400ddadf on core 0

Backtrace: 0x4008c434:0x3ffbe170 0x4008c665:0x3ffbe190 0x400ddadf:0x3ffbe1b0 0x40084771:0x3ffbe1d0 0x4014c113:0x3ffbc100 0x400dee8f:0x3ffbc120 0x4008a361:0x3ffbc140 0x40088b7d:0x3ffbc160

Rebooting...

Without the rest of the code, one can only guess..

I can post the rest, but no one ever tries it...

#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <SPIFFS.h>

//#include <esp_task_wdt.h>
#include <soc/rtc_wdt.h>

const char* ssid = "Wireless Controller";
const char* password = "12345678";


AsyncWebServer server(80);



void notFound(AsyncWebServerRequest *request)
{
    request->send(404, "text/plain", "Not found");
}


  
void action(AsyncWebServerRequest *request)
{
  Serial.println("ACTION!");

  int params = request->params(); // amount of params
  for (int i = 0; i < params; i++)
  {
    AsyncWebParameter* p = request->getParam(i);
    Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str());     
  }

  request->send(SPIFFS, "/index.html", String(), false);
}                   




IPAddress IP(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);






void setup()
{
   Serial.begin(115200);  // debugging
   Serial2.begin(9600, SERIAL_8N1, 16, 17); // Send data on pin 17
   delay(500);

//  esp_task_wdt_init(30, false);

//  rtc_wdt_protect_off();
//  rtc_wdt_disable();

  // Initialize SPIFFS
  if (!SPIFFS.begin(true))
  {
    Serial.println("An Error has occurred while mounting SPIFFS");
    return;
  }

  // Connect to Wi-Fi network with SSID and password
  Serial.print("Setting AP (Access Point)…");

  // Remove the password parameter, if you want the AP (Access Point) to be open
  WiFi.softAP(ssid, password);
  delay(2000);
  WiFi.softAPConfig(IP, gateway, subnet);
  IPAddress IP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(IP);




  // Route to load style.css file
  server.on("/style.css", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/style.css", "text/css");
  });







  // Index.HTML NAVIGATION BUTTIONS ************************************************


  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/index.html", String(), false);
  });


  server.on("/action", HTTP_POST, action);




  // Pictures *****************************************************************


  server.on("/0all.png", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/0all.png", "image/png");
  });
  
  server.on("/1circle.png", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/1circle.png", "image/png");
  });

  server.on("/2fspiral.png", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/2fspiral.png", "image/png");
  });
  
  server.on("/3ped.png", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/3ped.png", "image/png");
  });

  server.on("/4clover.png", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/4clover.png", "image/png");
  });




  server.onNotFound(notFound);

  server.begin();

  //  esp_task_wdt_init(30, false);
  rtc_wdt_protect_off();
  rtc_wdt_disable();
}





void loop()
{
  // May not need once loop contains something:
  vTaskDelay(10); //https://github.com/espressif/arduino-esp32/issues/595

}

task_wdt is NOT the watch dog timer of the ESP32. task_wdt is a process of the ESP32's OS, freeRTOS; a software OS WDT.

Install the ESP Exception Decoder, put your debug info into it and post the decoded results here.

core0 and if using WiFi means the WiFi stack got corrupted in some fashion or, the programmer put a task onto core0 and the programmer does not know what they are doing or ADC1 is being used while WiFi is being used.

you can remove the vTaskDelay from loop(). In fact if the OP is going to use freeRTOS it is recommended that loop() does not contain code. One reason is loop() on the ESP32 is given the lowest priority and loop() may not run for sometime. Another reason is that if loop() does not contain code, when the OS runs loop() then the OS will do memory clean up.

Edit to Add:

Before connecting to WiFI issue a WiFI.disconnect(). WiFi.disconnect() does 2 things.

Thing1 is it disconnectes the WiFi of the ESP32 from... blah blah blah.

The other thing, now this is the important thing, WiFi.disonnect() resets the WiFi stack to its default values. By issuing a WiFi disconnect() before connecting one makes sure the WiFi stack is clean.

Edit to Add: Use LittleFS instead of SPIFFS. SPIFFS' have been deprecated.

1 Like

This has proven to be a very reliable way for me to connect to WIFI. Hope it helps you.

void connectToWiFi()
{
  int TryCount = 0;
  while ( WiFi.status() != WL_CONNECTED )
  {
    TryCount++;
    WiFi.disconnect();
    WiFi.begin( SSID, PASSWORD );
    vTaskDelay( 4000 );
    if ( TryCount == 10 )
    {
      ESP.restart();
    }
  }
  WiFi.onEvent( WiFiEvent );
}

Edit to add:

if ( (wifiClient.connected()) && (WiFi.status() == WL_CONNECTED) )
    {

The best way to check for a valid WiFi connection.

I use this expanded version of WiFi callback when troubleshooting WiFI issues.

void WiFiEvent(WiFiEvent_t event)
{
   log_i( "[WiFi-event] event: %d\n", event );
  switch (event) {
        case SYSTEM_EVENT_WIFI_READY:
          log_i("WiFi interface ready");
          break;
        case SYSTEM_EVENT_SCAN_DONE:
          log_i("Completed scan for access points");
          break;
        case SYSTEM_EVENT_STA_START:
          log_i("WiFi client started");
          break;
        case SYSTEM_EVENT_STA_STOP:
          log_i("WiFi clients stopped");
          break;
    case SYSTEM_EVENT_STA_CONNECTED:
      log_i("Connected to access point");
      break;
    case SYSTEM_EVENT_STA_DISCONNECTED:
      log_i("Disconnected from WiFi access point");
      break;
        case SYSTEM_EVENT_STA_AUTHMODE_CHANGE:
          log_i("Authentication mode of access point has changed");
          break;
        case SYSTEM_EVENT_STA_GOT_IP:
          log_i ("Obtained IP address: %s",  WiFi.localIP() );
          break;
        case SYSTEM_EVENT_STA_LOST_IP:
          log_i("Lost IP address and IP address is reset to 0");
          //      vTaskDelay( 5000 );
          //      ESP.restart();
          break;
        case SYSTEM_EVENT_STA_WPS_ER_SUCCESS:
          log_i("WiFi Protected Setup (WPS): succeeded in enrollee mode");
          break;
        case SYSTEM_EVENT_STA_WPS_ER_FAILED:
          log_i("WiFi Protected Setup (WPS): failed in enrollee mode");
          //      ESP.restart();
          break;
        case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT:
          log_i("WiFi Protected Setup (WPS): timeout in enrollee mode");
          break;
        case SYSTEM_EVENT_STA_WPS_ER_PIN:
          log_i("WiFi Protected Setup (WPS): pin code in enrollee mode");
          break;
        case SYSTEM_EVENT_AP_START:
          log_i("WiFi access point started");
          break;
        case SYSTEM_EVENT_AP_STOP:
          log_i("WiFi access point  stopped");
          //      WiFi.mode( WIFI_OFF);
          //      esp_sleep_enable_timer_wakeup( 1000000 * 2 ); // 1 second times how many seconds wanted
          //      esp_deep_sleep_start();
          break;
        case SYSTEM_EVENT_AP_STACONNECTED:
          log_i("Client connected");
          break;
    case SYSTEM_EVENT_AP_STADISCONNECTED:
      log_i("WiFi client disconnected");
          break;
        case SYSTEM_EVENT_AP_STAIPASSIGNED:
          log_i("Assigned IP address to client");
          break;
        case SYSTEM_EVENT_AP_PROBEREQRECVED:
          log_i("Received probe request");
          break;
        case SYSTEM_EVENT_GOT_IP6:
          log_i("IPv6 is preferred");
          break;
        case SYSTEM_EVENT_ETH_GOT_IP:
          log_i("Obtained IP address");
          break;
    default: break;
  }
}

Correct, I've not tried your code. I see no reason to try your code until the other things have been looked into. I did read your code.

There are a couple of places where the code seems buggy:

You are also repeating "image/png" multiple times, a constant or PROGMEM would be better.

This is not relevant because a soft access point is created, correct?

Good luck.

For a soft access point? Is your information about connecting to WiFi relevant to my application?

If the ESP is not "cold booted", the WiFi interface may be active and thus it must be disconnected before it is re-configured and used.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.