Error trying to download large file using WiFiClient.connect() "Task watchdog got triggered"
Posted: Thu Apr 30, 2020 5:21 pm
I'm testing code downloading large files from a server (working toward an OTA function)
Error I'm getting -- midway through the download...
-> E (15787) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
-> E (15787) task_wdt: - async_tcp (CPU 0/1)
-> E (15787) task_wdt: Tasks currently running:
-> E (15787) task_wdt: CPU 0: IDLE0
-> E (15787) task_wdt: CPU 1: IDLE1
-> E (15787) task_wdt: Aborting.
-> abort() was called at PC 0x400e16af on core 0
...which, per this link, might be the result of the download process hogging resources, keeping the ESP from performing necessary functions?
I'm guessing the client.read() within the while() loop (in the code below) was the culprit.
Tried testing delay() / vTaskDelay() at various durations without any improvement.
Also, still new at C++ coming from JS, so lots of questions:
The code below is adapted from an Espressif OTA Example.
Error I'm getting -- midway through the download...
-> E (15787) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
-> E (15787) task_wdt: - async_tcp (CPU 0/1)
-> E (15787) task_wdt: Tasks currently running:
-> E (15787) task_wdt: CPU 0: IDLE0
-> E (15787) task_wdt: CPU 1: IDLE1
-> E (15787) task_wdt: Aborting.
-> abort() was called at PC 0x400e16af on core 0
...which, per this link, might be the result of the download process hogging resources, keeping the ESP from performing necessary functions?
I'm guessing the client.read() within the while() loop (in the code below) was the culprit.
Tried testing delay() / vTaskDelay() at various durations without any improvement.
Also, still new at C++ coming from JS, so lots of questions:
- Do delay() and/or vTaskDelay() actually free up the ESP32 to handle other tasks, or do they block the processing even further?
- Are delay() and vTaskDelay() different functions or (per this link) is delay() just a wrapper of vTaskDelay()
- Trying to work with char arrays instead of Strings, but having difficulty coercing them to do what I want in various contexts. Any advice in doing so greatly appreciated. (char_str()? String()? itoa()? wtf()?)
- Re IPAddress class: Are those just int arrays? How to turn them into a char or String value of that same IP address?
- I'm under the impression that variables declared in a C++ function are automatically freed up on the function's completion. Correct?
The code below is adapted from an Espressif OTA Example.
Code: Select all
String GetBigFile(){
WiFiClient thisClient;
IPAddress thisHost(192, 168, 1, 10);
char thisPath[]="/testBigFile.ino.esp32.bin"; //Big = about 800k OTA bin file
String thisPart, theseHeaders, thisBody;
if(!thisClient.connect(thisHost, 8465)){
Serial.println("Connection Failed");
return "{\"Error\":\"Connection Failed\"}";
}
Serial.println(thisPath);
Serial.println(String(thisPath));
Serial.println("Connection succeeded");
Serial.print("thisClient.available(): ");
Serial.println(thisClient.available());
String thisReq=String("GET ") + String(thisPath) + " HTTP/1.1\r\n" +
"Host: 192.168.1.10:8465\r\n" +
"Cache-Control: no-cache\r\n" +
"Connection: close\r\n\r\n";
Serial.println("thisReq: " + thisReq);
thisClient.print(thisReq);
unsigned long timeout = millis();
while(thisClient.available()==0) {
if(millis()-timeout > 5000){
Serial.println("Client timed out");
thisClient.stop();
Serial.println("Client timed out");
return "{\"Error\":\"Client timed out\"}";
}
}
Serial.println("Headers Begin");
thisPart="Header";
while(thisClient.available()){
Serial.println(thisClient.available());
if(thisPart=="Header"){
String thisLine=thisClient.readStringUntil('\n');
theseHeaders.concat(thisLine);
thisLine.trim();
if(!thisLine.length()){
Serial.println("Headers Complete:\n" + theseHeaders + "\n------\n");
thisPart="Body";
}
}else{ //Error happens in this block, after about 50 successful character reads with delay
char thisChar=thisClient.read();
thisBody.concat(thisChar);
//delay(10); //Tested at various durations to see if it adds to or frees up blocking. It seems to add further blocking?
//vTaskDelay(15); //Also tested, at various duration.
}
}
Serial.println("Body Complete");
thisClient.stop();
return "{\"Headers\":\"" + theseHeaders + "\",\"Body\":\"" + thisBody + "\"}";
}