user52814: I am using 3 Esp32 modules. One being master and other two being nodes.
Nodes are connecting to the master's AP. Master is connected with GSM module to execute the web api.
Master esp is having a Async Webserver which takes the http requests from the nodes and executes the appropriate web api. This web api returns the result and finally this result is sent back to the node as the response to the http request.
While running this code, Randomly on any request i face wdt reset.
Hence my question is, how should i handle the wdt resets and keep my program running softly.
E (32706) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (32706) task_wdt: - async_tcp (CPU 0/1)
E (32706) task_wdt: Tasks currently running:
E (32706) task_wdt: CPU 0: IDLE0
E (32706) task_wdt: CPU 1: async_tcp
E (32706) task_wdt: Aborting.
abort() was called at PC 0x400e1cc3 on core 0
Backtrace: 0x4008c434:0x3ffbe170 0x4008c665:0x3ffbe190 0x400e1cc3:0x3ffbe1b0 0x40084771:0x3ffbe1d0 0x4016aaf3:0x3ffbc0d0 0x400e307a:0x3ffbc0f0 0x4008a361:0x3ffbc110 0x40088b7d:0x3ffbc130

My Code Snippet is given below,
Master
HttpClient http(gsmClient, "www.mydummyserver.com", 80);
AsyncWebServer server(80);

const char* ssid = "ESP32-Access-Point";
const char* password = "123456789";
IPAddress ip(192,168,5,2);
IPAddress gateway(192,168,5,1);
IPAddress subnet(255,255,255,0);
const char* PARAM_MESSAGE = "message";

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

void setup() {

  Serial.begin(115200);
  WiFi.mode(WIFI_AP);
  delay(100);
  WiFi.softAPConfig(ip, gateway, subnet); 
  WiFi.softAP(ssid, password);

server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
        request->send(200, "text/plain", "Hello, world");
    });

 server.on("/myApi", HTTP_POST, [] (AsyncWebServerRequest *request) {

        String message;
        if (request->hasParam(PARAM_MESSAGE)) {
            message = request->getParam(PARAM_MESSAGE)->value();
        } else {
            message = "No message sent";
        }

        http.setTimeout(20000);
        String postData = "Param1=abcd&Param2=pqrs";
        http.beginRequest();
        http.post("http://www.mydummyserver.com/testapi.php");
        http.sendHeader("Content-Type", "application/x-www-form-urlencoded");
        http.sendHeader("Content-Length", postData.length());
        http.beginBody();
        http.print(postData);
        http.endRequest();
        int statusCode = http.responseStatusCode();
        String response = http.responseBody();

        Serial.print("Status code: ");
        Serial.println(statusCode);
        Serial.print("Response: ");
        Serial.println(response);
        request->send(200, "text/plain", "Response: " + message);

    });

 server.onNotFound(notFound);

    server.begin();

}

void loop() {

}

Node
HTTPClient httpClient;

void setup() {

  Serial.begin(115200);

  WiFi.begin("ESP32-Access-Point", "123456789");

  Serial.print("WiFi ");

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(10);

  }

  Serial.println("connected:" + WiFi.SSID());

}

void executeApi() {

  Serial.println("Executing Api...");

  httpClient.setTimeout(20000);
  httpClient.begin("http://192.168.5.2/myApi");
  httpClient.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  String contentStr = "Param1=abcd&Param2=pqrs";

  int httpResponseCode = httpClient.POST(contentStr);

  Serial.print("HTTP Response code: ");
  Serial.println(httpResponseCode);

  httpClient.end();

}

String cmd = "";
void loop() {

  if (Serial.available() > 0) {

    cmd = (Serial.readStringUntil('\n'));

    if (cmd.length() > 0) {

      if (cmd == "api") {
        executeApi();

      }

    }

  }

}

For sulutions i have tried following things,
a. I tried to write this into the loop() function.
 while(true){ 
   delay(1); 
 }

b. Tried disabling the wdt
disableCore0WDT()
disableCore1WDT()

but none of these giving good results.

user64075: The following recommendations, as you aren't providing enough relevant info:

Install ESP-exception decoder and analyse your backtrace - Post it here so we can see in detail what caused the wdt
AsyncWebServer tends to cause this behavior if a response takes too long; a well placed yield() sometimes helps to prevent this behavior - to analyse you need ESP-exeption decoder
As loop() is running on core1 some/no process (idle) on core0 can cause the behavior. You can look up "task assignment to cores" on how to manually distribute the tasks (or send a yield() timed to core0 to reset the wdt)
Placing time-outs in combination with sleep/deep sleep (although you don't seem to use them) are also causes for wdt resets
A hackey trick is to set CONFIG_ASYNC_TCP_USE_WDT 0, but it is OK for testing

If you look into async_tcp for the possible culprit you see one line xTaskCreateUniversal(_async_service_task, "async_tcp", 8192 * 2, NULL, 3, &_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE);
Here is an example of how I use it to prevent wdt resets. Place in setup():
disableCore0WDT();
disableCore1WDT();
disableLoopWDT(); // You forgot this one !

and because of this routine in the async_tcp lib:
static void _async_service_task(void *pvParameters) {
  lwip_event_packet_t * packet = NULL;
  for (;;) {
    if (_get_async_event(&packet)) {
      #if CONFIG_ASYNC_TCP_USE_WDT
      if (esp_task_wdt_add(NULL) != ESP_OK) {
        log_e("Failed to add async task to WDT");
      }           
      #endif
      _handle_async_event(packet);
      #if CONFIG_ASYNC_TCP_USE_WDT
      if (esp_task_wdt_delete(NULL) != ESP_OK) {
        log_e("Failed to remove loop task from WDT");
      }
      #endif
    }
  }
  vTaskDelete(NULL);
  _async_service_task_handle = NULL;
}

I set the `CONFIG_ASYNC_TCP_USE_WDT 0` and it works so far.


52814: <p>I am using 3 Esp32 modules. One being master and other two being nodes.
Nodes are connecting to the master's AP. Master is connected with GSM module to execute the web api.
Master esp is having a Async Webserver which takes the http requests from the nodes and executes the appropriate web api. This web api returns the result and finally this result is sent back to the node as the response to the http request.</p>

<p>While running this code, Randomly on any request i face wdt reset.</p>

<p>Hence my question is, how should i handle the wdt resets and keep my program running softly.</p>

<pre><code>E (32706) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (32706) task_wdt: - async_tcp (CPU 0/1)
E (32706) task_wdt: Tasks currently running:
E (32706) task_wdt: CPU 0: IDLE0
E (32706) task_wdt: CPU 1: async_tcp
E (32706) task_wdt: Aborting.
abort() was called at PC 0x400e1cc3 on core 0
Backtrace: 0x4008c434:0x3ffbe170 0x4008c665:0x3ffbe190 0x400e1cc3:0x3ffbe1b0 0x40084771:0x3ffbe1d0 0x4016aaf3:0x3ffbc0d0 0x400e307a:0x3ffbc0f0 0x4008a361:0x3ffbc110 0x40088b7d:0x3ffbc130
</code></pre>

<p>My Code Snippet is given below,</p>

<p><strong>Master</strong></p>

<pre><code>HttpClient http(gsmClient, "www.mydummyserver.com", 80);
AsyncWebServer server(80);

const char* ssid = "ESP32-Access-Point";
const char* password = "123456789";
IPAddress ip(192,168,5,2);
IPAddress gateway(192,168,5,1);
IPAddress subnet(255,255,255,0);
const char* PARAM_MESSAGE = "message";

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

void setup() {

  Serial.begin(115200);
  WiFi.mode(WIFI_AP);
  delay(100);
  WiFi.softAPConfig(ip, gateway, subnet); 
  WiFi.softAP(ssid, password);

server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
        request-&gt;send(200, "text/plain", "Hello, world");
    });

 server.on("/myApi", HTTP_POST, [] (AsyncWebServerRequest *request) {

        String message;
        if (request-&gt;hasParam(PARAM_MESSAGE)) {
            message = request-&gt;getParam(PARAM_MESSAGE)-&gt;value();
        } else {
            message = "No message sent";
        }

        http.setTimeout(20000);
        String postData = "Param1=abcd&amp;Param2=pqrs";
        http.beginRequest();
        http.post("http://www.mydummyserver.com/testapi.php");
        http.sendHeader("Content-Type", "application/x-www-form-urlencoded");
        http.sendHeader("Content-Length", postData.length());
        http.beginBody();
        http.print(postData);
        http.endRequest();
        int statusCode = http.responseStatusCode();
        String response = http.responseBody();

        Serial.print("Status code: ");
        Serial.println(statusCode);
        Serial.print("Response: ");
        Serial.println(response);
        request-&gt;send(200, "text/plain", "Response: " + message);

    });

 server.onNotFound(notFound);

    server.begin();

}

void loop() {

}
</code></pre>

<p><strong>Node</strong></p>

<pre><code>HTTPClient httpClient;

void setup() {

  Serial.begin(115200);

  WiFi.begin("ESP32-Access-Point", "123456789");

  Serial.print("WiFi ");

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(10);

  }

  Serial.println("connected:" + WiFi.SSID());

}

void executeApi() {

  Serial.println("Executing Api...");

  httpClient.setTimeout(20000);
  httpClient.begin("http://192.168.5.2/myApi");
  httpClient.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  String contentStr = "Param1=abcd&amp;Param2=pqrs";

  int httpResponseCode = httpClient.POST(contentStr);

  Serial.print("HTTP Response code: ");
  Serial.println(httpResponseCode);

  httpClient.end();

}

String cmd = "";
void loop() {

  if (Serial.available() &gt; 0) {

    cmd = (Serial.readStringUntil('\n'));

    if (cmd.length() &gt; 0) {

      if (cmd == "api") {
        executeApi();

      }

    }

  }

}
</code></pre>

<p>For sulutions i have tried following things,</p>

<p>a. I tried to write this into the loop() function.</p>

<pre><code> while(true){ 
   delay(1); 
 }
</code></pre>

<p>b. Tried disabling the wdt</p>

<pre><code>disableCore0WDT()
disableCore1WDT()
</code></pre>

<p>but none of these giving good results.</p>
 64075: <p>The following recommendations, as you aren't providing enough relevant info:</p>
<ul>
<li>Install <a href="https://github.com/me-no-dev/EspExceptionDecoder" rel="nofollow noreferrer">ESP-exception decoder</a> and analyse your backtrace - Post it here so we can see in detail what caused the wdt</li>
<li>AsyncWebServer tends to cause this behavior if a response takes too long; a well placed <code>yield()</code> sometimes helps to prevent this behavior - to analyse you need ESP-exeption decoder</li>
<li>As <code>loop()</code> is running on core1 some/no process (idle) on core0 can cause the behavior. You can look up &quot;task assignment to cores&quot; on how to manually distribute the tasks (or send a <code>yield()</code> timed to core0 to reset the wdt)</li>
<li>Placing time-outs in combination with sleep/deep sleep (although you don't seem to use them) are also causes for wdt resets</li>
<li>A hackey trick is to set <code>CONFIG_ASYNC_TCP_USE_WDT 0</code>, but it is OK for testing</li>
</ul>
<p>If you look into async_tcp for the possible culprit you see one line <code>xTaskCreateUniversal(_async_service_task, &quot;async_tcp&quot;, 8192 * 2, NULL, 3, &amp;_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE);</code></p>
<p>Here is an example of how I use it to prevent wdt resets. Place in <code>setup()</code>:</p>
<pre class="lang-cpp prettyprint-override"><code>disableCore0WDT();
disableCore1WDT();
disableLoopWDT(); // You forgot this one !
</code></pre>
<p>and because of this routine in the async_tcp lib:</p>
<pre class="lang-cpp prettyprint-override"><code>static void _async_service_task(void *pvParameters) {
  lwip_event_packet_t * packet = NULL;
  for (;;) {
    if (_get_async_event(&amp;packet)) {
      #if CONFIG_ASYNC_TCP_USE_WDT
      if (esp_task_wdt_add(NULL) != ESP_OK) {
        log_e(&quot;Failed to add async task to WDT&quot;);
      }           
      #endif
      _handle_async_event(packet);
      #if CONFIG_ASYNC_TCP_USE_WDT
      if (esp_task_wdt_delete(NULL) != ESP_OK) {
        log_e(&quot;Failed to remove loop task from WDT&quot;);
      }
      #endif
    }
  }
  vTaskDelete(NULL);
  _async_service_task_handle = NULL;
}

I set the `CONFIG_ASYNC_TCP_USE_WDT 0` and it works so far.
</code></pre>
