Reboot when processor processing large files
I get on a stochastic base (mostly after closing the browser, wait 1 hour, open again.. sometimes a reboot of the esp32 (wemos d1 r32) on the moment that we open the index web-page. Just refreshing a page goes most of the times without problems there is no memory leak.... Power is supplied seperately (so no wifi power issue) ESPFreeHeap-126612 ESPMaxAllocHeap-87816 ESPMinFreeHeap-98472 SPIFFS totalBytes 775841 SPIFFS usedBytes 350145
The error trace shows in the middle the SPIFFS_LIB_Create_HTML_Drop_Down(String&, String, String) but the lines above are beyond my understanding
Could someone perhaps take some time to explain what is happening in the error trace lines above SPIFFS_LIB_Create_HTML_Drop_Down(String&, String, String) and hopefully give an understanding why this error is happening and results in a reboot?
My feeling is telling: it has to do with the stack, but i do not understand Why.... i already increased the available memory but that did not gave any improvement.
so in the web-page , i have the text $DROP_DOWN_FILE_DOWNLOAD$ ( characters are updated due to css characters^_^) to identify for the processor the location of the created html drop down with file-names ....
************************ ERROR****************************
[I][SPIFFS_LIB.ino:719] SPIFFS_LIB_Create_HTML_Drop_Down(): Add all File names to the array FileList[]
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400943a7 PS : 0x00060433 A0 : 0x80094958 A1 : 0x3ffe7e30
A2 : 0x00fe9ca4 A3 : 0x3ffe9d4c A4 : 0x00000002 A5 : 0x00000001
A6 : 0x00060423 A7 : 0x00000000 A8 : 0x00000001 A9 : 0x00000001
A10 : 0x3ffe9e98 A11 : 0x3ffbd624 A12 : 0x3ffe9bc0 A13 : 0x3ffe2b14
A14 : 0x3ffe7ef0 A15 : 0x3ffe8bc4 SAR : 0x00000019 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00fe9ca4 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0x00000000
ELF file SHA256: 0000000000000000
Backtrace: 0x400943a7:0x3ffe7e30 0x40094955:0x3ffe7e50 0x40094f3a:0x3ffe7e70 0x40082c76:0x3ffe7e90 0x400879a1:0x3ffe7eb0 0x4000bec7:0x3ffe7ed0 0x40149be9:0x3ffe7ef0 0x40194696:0x3ffe7f10 0x400e44b1:0x3ffe7f30 0x400e4423:0x3ffe7f50 0x400db6e6:0x3ffe7f80 0x400dbd95:0x3ffe80d0 0x401ba1a9:0x3ffe8130 0x400ee744:0x3ffe8150 0x400ee9d1:0x3ffe81e0 0x401bb4fa:0x3ffe8230 0x400ea8f9:0x3ffe8250 0x400f0513:0x3ffe8270 0x400f0680:0x3ffe82a0 0x400f0d61:0x3ffe82c0 0x4009171a:0x3ffe82f0
Rebooting... ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
PC: 0x400943a7: get_prev_free_block at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap.c line 131 EXCVADDR: 0x00fe9ca4
Decoding stack results 0x400943a7: get_prev_free_block at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap.c line 131 0x40094955: multi_heap_free_impl at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap.c line 484 0x40094f3a: multi_heap_free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 225 0x40082c76: heap_caps_free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c line 268 0x400879a1: _free_r at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/syscalls.c line 42 0x40149be9: vfs_spiffs_closedir at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/spiffs/esp_spiffs.c line 611 0x40194696: closedir at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/vfs/vfs.c line 628 0x400e44b1: VFSFileImpl::close() at C:\Users\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\FS\src\vfs_api.cpp line 289 0x400e4423: fs::File::close() at C:\Users\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\FS\src\FS.cpp line 136 0x400db6e6: SPIFFS_LIB_Create_HTML_Drop_Down(String&, String, String) at C:\Users\OneDrive\Documents\Arduino\QNAP_4VX_SHIELD\Main/SPIFFS_LIB.ino line 728 0x400dbd95: processor(String const&) at C:\Users\OneDrive\Documents\Arduino\QNAP_4VX_SHIELD\Main/WIFI_LIB.ino line 115 0x401ba1a9: std::_Function_handler ::_M_invoke(std::_Any_data const&, String const&) at c:\users\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0/functional line 1857 0x400ee744: AsyncAbstractResponse::_fillBufferAndProcessTemplates(unsigned char*, unsigned int) at c:\users\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0/functional line 2271 0x400ee9d1: AsyncAbstractResponse::_ack(AsyncWebServerRequest*, unsigned int, unsigned int) at C:\Users\OneDrive\Documents\Arduino\libraries\ESPAsyncWebServer-master\src\WebResponses.cpp line 315 0x401bb4fa: AsyncWebServerRequest::_onAck(unsigned int, unsigned int) at C:\Users\OneDrive\Documents\Arduino\libraries\ESPAsyncWebServer-master\src\WebRequest.cpp line 201 0x400ea8f9: std::_Function_handler >::_M_invoke(const std::_Any_data &, , , , ) at C:\Users\OneDrive\Documents\Arduino\libraries\ESPAsyncWebServer-master\src\WebRequest.cpp line 73 0x400f0513: AsyncClient::_sent(tcp_pcb*, unsigned short) at c:\users\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0/functional line 2271 0x400f0680: AsyncClient::_s_sent(void*, tcp_pcb*, unsigned short) at C:\Users \OneDrive\Documents\Arduino\libraries\AsyncTCP\src\AsyncTCP.cpp line 1222 0x400f0d61: _async_service_task(void*) at C:\Users\OneDrive\Documents\Arduino\libraries\AsyncTCP\src\AsyncTCP.cpp line 168 0x4009171a: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 143
************************ programm ****************************
server.on("/index", HTTP_ANY, [](AsyncWebServerRequest *request){ request->send_P(200, "text/html", MAIN_page, processor); });
void MyWifidummy(){int p = 100;}
String processor(const String& var){
//Serial.println("reading var:" + var); ESP_LOGI( TAG01 , "Processor reading var: = %s", var.c_str() ); if(var == "DROP_DOWN_FILE_DOWNLOAD"){ String My_HTML_Dropdown; // define the buffer for the HTML text String IDname = "MyDownloads"; // define the name for the drop-down SPIFFS_LIB_Create_HTML_Drop_Down( My_HTML_Dropdown ,IDname,"download"); ESP_LOGI( TAG01 ,"Size of Drop_Down MyDownloads string: %i [byte] " , (10+(2*My_HTML_Dropdown.length())) ); // around 5kB...... MyWifidummy(); // for debugging stacktrace only return My_HTML_Dropdown; }
return String(); }
void SPIFFS_LIB_Create_HTML_Drop_Down( String &Dropdown, String IDnm,String DD_Func){ File root; File file; int nFiles = 0; unsigned long Functiondurationtime; String *FList; String *FcList; String *FsList;
Functiondurationtime = millis();
ESP_LOGI( TAG01 ,"Create dropdown for: %s", DD_Func);
delay(100);
if (SPIFFS.begin()) {
// count the number of file names
root = SPIFFS.open("/");
file = root.openNextFile();
while(file){
nFiles++;
file = root.openNextFile();
}
root.close();
file.close();
ESP_LOGI( TAG01 ,"we have %i Files",nFiles );
// reserve an array to contain the number of file names
FList = new String[nFiles];
// fill the array with file names
ESP_LOGI( TAG01 ,"Add all File names to the array FileList[]");
nFiles = 0;
root = SPIFFS.open("/");
file = root.openNextFile();
while(file){
FList[nFiles] = file.name();
nFiles++;
file = root.openNextFile();
}
root.close();
file.close();
// list the file names
// OK, LETS SORT THE STUFF
for(int i = 0;i < nFiles ;i++) {
if (Debug_ShowAll) ESP_LOGI( TAG01 ,"Unsorted File name: %s", FList[i].c_str() );
}
// do a bubble sort
for (uint8_t c = 0; c < nFiles - 1; c++) {
for (uint8_t d = 0; d < nFiles - c - 1; d++) {
if ( FList[d].charAt(1) > FList[d+1].charAt(1) ) { // compare if the next Character has a higher ascii value
for (uint8_t e = 0; e < 1; e++) { // swap both values & index
String tempval = FList[d];
FList[d] = FList[d+1];
FList[d+1] = tempval;
}
}
}
}
// now er have an acending list but ..... we start with Capitals and not with small
FcList = new String[nFiles]; // reserve space for files beginning with a Capital
FsList = new String[nFiles]; // reserve space for files beginning with a Small
int p = 0;
int q = 0;
// lets split the capitals and the small's into 2 array's
for(int i = 0;i < nFiles ;i++) {
// move all files with a Capital to FcList
if ( FList[i].charAt(1) < 'a') {
FcList[p] = FList[i]; p++;
FList[i] = ""; // remove this file name
}
// it is not a capital so lets add it to small
FsList[q] = FList[i]; q++;
}
//Now put all together
int t=0;
for(int i = 0;i < nFiles ;i++) {
if ( FsList[i].charAt(1) > 0x01 ) {
FList[t] = FsList[i]; t++;
}
}
delete[] FsList;
for(int z = 0;z < nFiles ;z++) {
if ( FcList[z].charAt(1) > 0x01 ) {
FList[t] = FcList[z]; t++;
}
}
delete[] FcList;
// list the result of the sorted file names
for(int i = 0;i < nFiles ;i++) {
if (Debug_ShowAll) ESP_LOGI( TAG01 ,"sorted File name: %s", FList[i].c_str() );
}
String DD_FS1,DD_FS2,DD_FS3 ;
if ( DD_Func == "delete"){
//delete
DD_FS1 = "' onchange='request_MydeleteFile(this)'>\n";
DD_FS2 = "function request_MydeleteFile(Obj){\n";
DD_FS3 = " let text = \"Delete the file: \" +reqfile +\" Either OK or Cancel.\";\n";
DD_FS3 += " if (confirm(text) == true) { \n window.location.href=\"/DeleteFromWemos?Parm1=aa&Parm2=/\"+reqfile;\n";
DD_FS3 += " //text = 'You pressed OK!';\n";
DD_FS3 += " } else {};//You canceled!\n";
}
else if ( DD_Func == "download"){
//download
DD_FS1 = "' onchange='request_MyDownloadFile(this)'>\n";
DD_FS2 = "function request_MyDownloadFile(Obj){\n";
DD_FS3 = " window.location.href='/SendFileToPC?Parm1=aa&Parm2=/'+reqfile;\n";
}
else {
ESP_LOGE( TAG01 ,"Error: Wrong drop-down selection parameter: %s", DD_Func);
}
// create the drop-down list
Dropdown += "<select name='";
Dropdown += IDnm;
Dropdown += "' id='";
Dropdown += IDnm;
Dropdown += DD_FS1;
for(int i = 0;i < nFiles ;i++) {
Dropdown += " <option value='" ;
Dropdown += FList[i].c_str();
Dropdown += "' >";
String tmp = FList[i].c_str();
tmp.remove(0,1); // remove the first character of this string as it is an slash / from the filename
Dropdown += tmp;
Dropdown += "</option>";
Dropdown += "\n";
}
Dropdown += "</select>\n";
delete[] FList;
// add the script to it
Dropdown += "<script language='javascript' type='text/javascript'>\n" ;
Dropdown += "// lets try to upload a file to or delete from a the esp32 \n" ;
Dropdown += DD_FS2 ;
Dropdown += " var reqfile = Obj.options[Obj.selectedIndex].text ;\n" ;
Dropdown += DD_FS3 ;
Dropdown += "}\n";
Dropdown += "</script>\n";
//ESP_LOGI( TAG01 ,"html drop-down size: %i[characters] data:\n%s", Dropdown.length(), Dropdown.c_str() );
ESP_LOGI( TAG01 , "Creating the dropdown %s has taken : %lu mSec", IDnm.c_str(), ( millis() - Functiondurationtime ) );
}
}