2

The aim is to display a non-static html page depending on some variable condition.

The code I created hast the problem, that the esp8266 is ressetting in the moment I request the page.

const char htmlIndexHeader[] PROGMEM = R"=====(
<html>
<head>
 <meta http-equiv="content-type" content="text/html;charset=UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title>Test</title>
</head>
<body>
 <p>Hello World</p>
 <ol>
)=====";
const char htmlIndexProgress1[] PROGMEM = R"=====(
 <li>lorem</li>
)====="; 
const char htmlIndexProgress2[] PROGMEM = R"=====(
 <li>ipsum</li>
)====="; 
const char htmlIndexFooter[] PROGMEM = R"=====(
 </ol>
</body>
</html>
)====="; 
char htmlIndexAll[2000]; 
void handleRoot() 
{
 Serial.println("GET /");
 strcpy(htmlIndexAll, htmlIndexHeader);
 if(var1==true)
 {
 strcat(htmlIndexAll, htmlIndexProgress1);
 }
 if(var2==true)
 {
 strcat(htmlIndexAll, htmlIndexProgress2);
 } 
 strcat(htmlIndexAll, htmlIndexFooter);
 server.send(200, "text/html", htmlIndexAll);
}

If I display a static page the esp8266 does not restart at page request.

asked Dec 14, 2019 at 12:40
2
  • 2
    try strcpy_P and strcat_P Commented Dec 14, 2019 at 14:15
  • 1
    @Juraj it is working! Commented Dec 14, 2019 at 18:27

1 Answer 1

2

Compiler can't differentiate the PROGMEM strings from constant strings in SRAM strings. Both are const char*. But the PROGMEM string must be handled differently. For that reason _P variants of functions exists.

You should use stcpy_P and strcat_P functions.

Note: On esp8266 some functions of Arduino core use a trick to identify PROGMEM strings by their specific address range.

answered Dec 14, 2019 at 18:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.