-->
Page 1 of 1

Update Arduino lib v2.5.2 -> v2.6.2 crashes in R() strings

PostPosted: Wed Dec 11, 2019 7:03 pm
by Skoon
I am using an Adafruit Feather HUZZAH ESP8266 board to act as a webserver. I had a bunch of code working using Arduino interface using the board library v2.5.2. I recently reopened the project to make some changes, and in the process updated the board library to v2.6.2. What I found is that my unchanged project that was working fine previously now started crashing / resetting when using the upgraded library / tools.

Using some Serial output, ESP Stack Debugger, I was able to track this down to the use of PROGMEM R() strings that contained the HTML to be served.

This can be repro'd by using the EXAMPLE -> ESP8266WebServer -> HelloServer sample. Just make the following change to handling the root request:

Code: Select allconst char g_HTML[] PROGMEM = R"test(
<!DOCTYPE HTML>
<html>
  <body>
      Sample Text
  </body>
</html>
)test";

void handleRoot() {
  digitalWrite(led, 1);
  String resp = g_HTML;
 
  server.send(200, "text/html", resp);
  digitalWrite(led, 0);
}


Not sure if this is an intentional change in the toolset, or if I am doing something wrong here, but would love to hear any ideas on what I may be able to do to get this working again so I don't have to stay at a downgraded version.

Thanks in advance!

Re: Update Arduino lib v2.5.2 -> v2.6.2 crashes in R() strin

PostPosted: Wed Dec 25, 2019 6:39 am
by straetch
Same problem here.
Example code below comes from the "Hello world" example, adapted for use of PROGMEM.
I need to copy PROGMEM to an intermediate String because that string must be manipulated before sending.

This code works ok with v2.5.2.
With v.2.6.3 the program crashes.
If I use a string literal in server.send(200, "text/plain", "Hello world"); it works (but that is not the intention).
If I remove all references to esp8266Webserver, there is no crash and the String s is printed nicely in the serial monitor.

My interpretation is that esp8266webserver cannot handle a string originating from PROGMEM as of v2.6.
Is this a bug?
Can I copy the string from PROGMEM in another way that does not hurt esp8266webserver?
For the moment I have to stay with esp8266 libs version 2.5.2.

Using Arduino 1.8.10, NodeMCU 1.0 .

Code: Select all...
#include <ESP8266WebServer.h>   // Include the WebServer library

ESP8266WebServer server(80);    // Create a webserver object that listens for HTTP request on port 80

const char HoofdPagina[] PROGMEM = R"=====(
<!DOCTYPE html>
<html>
<head>
<titel>Exper met PROGMEM</titel>
</head>
<body>
<h2>Hello world!</h2>
</body>
</html>
)=====";

void handleRoot();              // function prototypes for HTTP handlers
void handleNotFound();

void setup(void){
...
  String s = HoofdPagina;
  Serial.println(s);
  server.on("/", handleRoot);               // Call the 'handleRoot' function when a client requests URI "/"
  server.onNotFound(handleNotFound);

  server.begin();                           // Actually start the server
  Serial.println("HTTP server started");
}
void loop(void){
   server.handleClient();                    // Listen for HTTP requests from clients
}

void handleRoot() {
  String s = HoofdPagina;
  Serial.println(s);
  server.send(200, "text/html", s);   // Send HTTP status 200 (Ok) and send some text to the browser/client
}

void handleNotFound(){
  server.send(404, "text/plain", "404: Not found");
}