esp32 webserver crashes after ~ 50 minutes ---HELP

I've been struggling with the webserver part of a project. Originally this project ran on a MEGA2560 but needed external wifi (via esp8266) and RTC. All function are now re-coded into a ESP32 WROVER (via Arduino IDE)..

Everything was going well except the web server part of the code crashes in about 50min and the EXP32 exception decoder has not been helpful.

I was hoping of you experts out there could take a look at my server code to see if you can spot anything obvious the could lead to this problem???

Many thanks

TOM

void pID() {

xTaskCreatePinnedToCore(

taskOne, /* Task function. /
"TaskOne", /
String with name of task. /
30000, /
Stack size in bytes. /
NULL, /
Parameter passed as input of the task /
1, /
Priority of the task. */
NULL,
0);

pause;

}

void taskOne( void * parameter )
{

for(;;){

digitalWrite(blUe, LOW);
digitalWrite(amBer, LOW);
digitalWrite(grEen, HIGH);
digitalWrite(reD, HIGH);

//WEB SERVER STARTS HERE

digitalWrite(blUe, LOW);
digitalWrite(amBer, LOW);
digitalWrite(grEen, HIGH);
digitalWrite(reD, HIGH);

bool currentLineIsBlank = true;

String readString;

// listen for incoming clients
WiFiClient client = server.available();

if (client) {

Serial.println("new client");
// an http request ends with a blank line
currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();

readString += c;

// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply

if (c == '\n' && currentLineIsBlank) {

client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html; charset=utf-8");
client.println("Access-Control-Al-Origin: http://192.168.4.2:80");
client.println("Connection: close"); // the connection will be closed after completion of the response

client.println("Refresh: 5"); // refresh the page automatically every 2 sec
client.println("");

client.println("");
client.println("");

client.println("");
client.println("");
client.println("

iQUEbbq FIREWORKS REPORTS

"); client.println("

Cook Temp Target = "); client.print(CT); client.println(" °F

"); client.println("

GRID TEMPERATURE IS

"); client.println("

"); client.print(gridT); client.println(" °F

"); client.println("

PRB1 TEMP = "); client.print(prBt1); client.println(" PRB2 TEMP ="); client.println(prBt2); client.println("

"); client.println("

THE COOKING TIME IS

"); client.println(Webt); client.println("

"); //client.println("

"); //client.println("

"); client.println("");

if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}

// give the web browser time to receive the data
delay(1000);
// close the connection:
client.stop();
Serial.println("client disconnected");

}}}}

{ if (analogRead(36)<= 50)
{
Serial.println("restarting");
for (int i = 0 ; i < 10; i++)
{
EEPROM.write(i, 0);

}
setup();
}
}
}
}

SERVER.txt (8.28 KB)

Well, the string class is notorious for that, and you've used it liberally...

  client.println("<link rel="stylesheet" type="text/css" href="style.css">");

Which compiler is able to understand this very strange construct?

aarg:
Well, the string class is notorious for that, and you've used it liberally...

WOW! Never ran into that comment before -- thanks for the catch :-). Can you elaborate on alternative approaches??

TOM

Use C-strings.

You might post your code using code tags for easier trouble shooting. Like others have said, it is surprising you don't get compile errors with the code you posted. With the ESP32, the "String" comment may just be a red herring rabbit hole for you to go down.

Even though the ESP32 has lots of RAM for Strings to play in, I see no destructor for 'readstring'. So it may leave garbage lying around after every call to "taskOne". That would be a problem even on a PC.

aarg:
Even though the ESP32 has lots of RAM for Strings to play in, I see no destructor for 'readstring'. So it may leave garbage lying around after every call to "taskOne". That would be a problem even on a PC.

Thanks aarg! I'll look for that. May just have missed it but then I could just as easily not put one in cause I don't know what I'm doing!

TOM

"Thanks aarg! I'll look for that. May just have missed it but then I could just as easily not put one in cause I don't know what I'm doing!"

You might put something similar to the below at the end of your code when the Strings are no longer needed.

client.stop();

/////////////////////
//clearing string for next read
readString="";
teststring="";
finalstring="";

Okay, I have to admit, after some research I found that the String object's memory is automatically deallocated by the String class destructor, after going out of scope of the block it's used in. In this case, it would be the end of the function. So it's not likely to be causing any problem.