ESP32: Getting Guru Meditation Error because having an extremly long string (~15.000 characters long)

0

I've written a little program, which in a loop first sends a POST-request to a special machine, the machine returns an other API-path in its response header, afterwards I can execute a GET-request on that API path and get an extremly long string (~ about 15.000 characters). This works pretty fine - the string is returned and I can print it afterwards. But then something really strange happens: After each print of the string, my ESP seems to restart somewhy. Please see Output:

005    03.07.     08:25
========================
ENDE NC NL

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x4015c44c  PS      : 0x00060430  A0      : 0x800d30f2  A1      : 0x3ffb1dc0  
A2      : 0x3ffb1f10  A3      : 0x00000000  A4      : 0x00003de8  A5      : 0x00003de8  
A6      : 0x3ffd9098  A7      : 0x00003de8  A8      : 0x800d5105  A9      : 0x3ffb1da0  
A10     : 0x3ffd7938  A11     : 0x3f4015a2  A12     : 0x00000002  A13     : 0x0000ff00  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000010  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff  

Backtrace: 0x4015c44c:0x3ffb1dc0 0x400d30ef:0x3ffb1de0 0x400d3161:0x3ffb1e00 0x400d1ae2:0x3ffb1e20 0x400d6301:0x3ffb1fb0 0x40088b9d:0x3ffb1fd0

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5816
entry 0x400806ac
Connecting

ENDE NC NL is the last line of the string, one line is maximal 24 characters long and ends with \n (LF), the program starts with Connecting.

If I do not print the string directly, but first do some string "manipulation" operations and than try to print the manipulation result, the first 2 or 3 rounds the Guru Meditation Error is shown, then suddenly the ouput changes to the following:

Connecting
..
Connected to WiFi network with IP Address: 192.168.200.244
Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.
POST-Request to: https://192.168.200.101/api/vdai-daten
HTTP Response code: 201
Header Payload: /api/vdai-daten/vdai-daten.txt
=> GET-Request to: https://192.168.200.101/api/vdai-daten/vdai-daten.txt
2nd HTTP Response code: 200
Guru Meditation Error: Core  1 panic'ed (Unhandled debug exception)
Debug exception reason: Stack canary watchpoint triggered (loopTask) 
Core 1 register dump:
PC      : 0x400d55b4  PS      : 0x00060236  A0      : 0x800d57e9  A1      : 0x3ffaf5c0  
A2      : 0x3ffb005c  A3      : 0x00000025  A4      : 0x00000000  A5      : 0x0000ff00  
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x80000000  A9      : 0x3ffaf5a0  
A10     : 0x3ffb0050  A11     : 0x3f4016d2  A12     : 0x00000001  A13     : 0x3ffb1cc0  
A14     : 0x00000000  A15     : 0x3ffb0060  SAR     : 0x0000000a  EXCCAUSE: 0x00000001  
EXCVADDR: 0x00000000  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0x00000000  

Backtrace: 0x400d55b4:0x3ffaf5c0 0x400d57e6:0x3ffaf5e0 0x400d1afd:0x3ffaf600 0x400d63e9:0x3ffb1fb0 0x40088b9d:0x3ffb1fd0

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5816
entry 0x400806ac
Connecting
..
Connected to WiFi network with IP Address: 192.168.200.244
Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.
POST-Request to: https://192.168.200.101/api/vdai-daten
HTTP Response code: 201
Header Payload: /api/vdai-daten/vdai-daten.txt
=> GET-Request to: https://192.168.200.101/api/vdai-daten/vdai-daten.txt
2nd HTTP Response code: 200
***ERROR*** A stack overflow in task loopTask has been detected.
abort() was called at PC 0x4008c69c on core 1

Backtrace: 0x4008c454:0x3ffaf430 0x4008c685:0x3ffaf450 0x4008c69c:0x3ffaf470 0x40089768:0x3ffaf490 0x4008b3cc:0x3ffaf4b0 0x4008b382:0x833dcfb1

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5816
entry 0x400806ac
Connecting

Anyone had something like this before or can explain what is happening/wrong and how I can handle / deal with this 15.000 characters long string?^^

Would be really happy for every answer,

Best regards

P.S.: Please finally let me add my code... the commented part is the string "manipulation" part.

#include <WiFi.h>
#include <HTTPClient.h>

const char* ssid = "MyWiFiName";
const char* password = "MyWiFiPassword";

const char* serverName = "https://192.168.200.101/api/vdai-daten";

unsigned long lastTime = 0;

unsigned long timerDelay = 5000;

const char * headerKeys[] = {"HeaderKey"} ;
const size_t numberOfHeaders = 1;

String payload;

void setup() {
  Serial.begin(115200);

  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());

  Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");
}

void loop() {
  if ((millis() - lastTime) > timerDelay) {
    //Check WiFi connection status
    if(WiFi.status()== WL_CONNECTED){
      HTTPClient http;

      Serial.print("POST-Request to: ");
      Serial.println(serverName);

      http.begin(serverName);

      http.collectHeaders(headerKeys, numberOfHeaders);      
      http.setAuthorization("Username", "Password");

      http.addHeader("Content-Type", "application/x-www-form-urlencoded");
     
      // Send HTTP POST request
      int httpResponseCode = http.POST("kassierung=false");
      
      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);

      String headerServer = http.header("HeaderKey");
      Serial.print("Header Payload: ");
      Serial.println(headerServer); 
    
      // Free resources
      http.end();

      HTTPClient http2;
      String newServerName = "https://192.168.200.101" + headerServer;
      Serial.print("=> GET-Request to: ");
      Serial.println(newServerName);
      http2.begin(newServerName.c_str());
      http2.setAuthorization("Username", "Password");
      httpResponseCode = http2.GET();
      Serial.print("2nd HTTP Response code: ");
      Serial.println(httpResponseCode);
      Serial.println("=> Big string: ");
      payload = http2.getString();
      Serial.println(payload);

      /*
      //Count amount of lines
      int counter = 0;
      for (int i=0; i < payload.length(); i++){ 
        if(payload.charAt(i) == '\n'){ 
          counter++;
        }
      }
  
      //Divide big string into a array, where each entry is one line
      String sa[counter]; 
      int r=0; 
      int t=0;
      for (int i=0; i < payload.length(); i++){ 
        if(payload.charAt(i) == '\n') { 
          sa[t] = payload.substring(r, i); 
          r=(i+1); 
          t++; 
        }
      }

      Serial.println("=> First line: ");
      Serial.println(sa[0]);
      */
  
      http2.end();      
    }
    else {
      Serial.println("WiFi Disconnected");
    }
    lastTime = millis();
  }
}
c++
string
runtime-error
stack-overflow
esp32
asked on Stack Overflow Dec 9, 2020 by Sam

1 Answer

0

It's clearly a stack overflow issue!

Either use malloc'ed memory for storing string instead OR increase task stack size for loopTask to about 20K.

answered on Stack Overflow Dec 14, 2020 by Vikram Dattu

User contributions licensed under CC BY-SA 3.0