arduinoesp8266esp32progmem

PROGMEM error on MacOS High Sierra Arduino Mac 1.8.5


I'm using MacBook Pro running on MacOS High Sierra.

There is a problem whenever i tried to upload Arduino code containing PROGMEM to store raw HTML string (Arduino Mac 1.8.5) to my ESP board. The board that i'm using is ESP8266 LoLin V3.

Exception (3) is raised in the Serial Monitor whenever i access the IP address of the ESP on the web browser. I've also tried to upload the same exact code using Windows version of Arduino for Windows(1.8.5) and the webpage can be displayed perfectly fine.

Code:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

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

ESP8266WebServer server ( 80 );

const char homepage[] PROGMEM = R"(
  <!DOCTYPE html>
  <html>
  <body>
  <h1>Mac can't compile PROGMEM properly!</h1>
  <h3>try to upload this code to any ESP8266 on a Mac and see the error!</h3>
  <h3>Exception (3)
  LoadStoreErrorCause
  Processor internal physical address or data error during load or store!</h3>
  <h3>Windows can easily compile this and read the file perfectly on ESP8266!</h3>
  </body>
  </html>
)";

void handleRoot() {
  String page = homepage;
  server.send(200, "text/html", page); //Send web page
}

void setup ( void ) {
    Serial.begin ( 115200 );
    WiFi.mode ( WIFI_STA );
    WiFi.begin ( ssid, password );
    Serial.println ( "" );
    // Wait for connection
    while ( WiFi.status() != WL_CONNECTED ) {
        delay ( 500 );
        Serial.print ( "." );
    }
    Serial.println ( "" );
    Serial.print ( "Connected to " );
    Serial.println ( ssid );
    Serial.print ( "IP address: " );
    Serial.println ( WiFi.localIP() );

    if ( MDNS.begin ( "esp8266" ) ) {
        Serial.println ( "MDNS responder started" );
    }
    server.on ( "/", handleRoot );
    server.begin();
    Serial.println ( "HTTP server started" );
}

void loop ( void ) {
    server.handleClient();
}

Error raised is as follows:

Exception (3):
epc1=0x40209d64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x4023ad32 depc=0x00000000

ctx: cont
sp: 3ffefb20 end: 3ffefe10 offset: 01a0

>>>stack>>>
3ffefcc0:  3ffe8b02 3ffeea80 3ffefd00 40207729
3ffefcd0:  00000001 00000001 3ffefd00 40207776
3ffefce0:  4023ad32 3ffefd40 3ffefd40 402076ab
3ffefcf0:  3fff10d4 00000001 3fff1044 4020206e
3ffefd00:  3fff118c 0000018f 00000182 4010020c
3ffefd10:  00000001 00000001 3ffefd40 4020836e
3ffefd20:  00000000 00000000 3fff1044 40204406
3ffefd30:  3fff1044 3ffeea9c 3fff1044 40204442
3ffefd40:  00000000 00000000 00000000 40207858
3ffefd50:  3fff1044 3ffeea9c 3ffeea58 402044c9
3ffefd60:  3fff10d4 0000000f 00000001 00000000
3ffefd70:  00000000 00000013 3ffeea5c 40203058
3ffefd80:  3ffeea9c 00000001 3ffeedf0 3ffeea80
3ffefd90:  00000001 00000000 40203964 0000000a
3ffefda0:  00000000 3fff0e5c 3ffeea58 3ffeeddc
3ffefdb0:  00000001 3ffeea80 3ffeea58 402046c0
3ffefdc0:  40107058 00000000 00001388 40208364
3ffefdd0:  00000000 3fff0e5c 00000000 feefeffe
3ffefde0:  3fffdad0 00000000 3ffeedd4 402021d0
3ffefdf0:  3fffdad0 00000000 3ffeedd4 402080e4
3ffefe00:  feefeffe feefeffe 3ffeedf0 40100710
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld

Can anyone here using a Mac try to upload the code on your ESP8266 and see if you get the same error as mine? Can anyone with a good knowledge on PROGMEM and ESP8266 help me out with this issue?


Solution

  • In your program you have

    void handleRoot() {
      String page = homepage;
      server.send(200, "text/html", page); //Send web page
    }
    

    This should be

    void handleRoot() {
      String page = FPSTR(homepage);
      server.send(200, "text/html", page); //Send web page
    }
    

    Add the FPSTR() and it will work properly. Without it your program can't properly dereference the string that you stored in Flash.

    You can find more about this at https://arduino-esp8266.readthedocs.io/en/latest/PROGMEM.html