ESP8266 - EEPROM and SPIFFS are not persistent

Hi together,

I have a problem with storing a single string in the EEPROM of my ESP8266 (I also tried another ESP8266). It seams to work without a reboot. But after a reboot, all the data is gone. I think I will lose my mind very soon. :stuck_out_tongue: I am working on this for 2 days now... When I tried to use SPIFFS instead, I had the same problem.

Here is my example-code, that is not working. Can you tell me why, please?

#include <EEPROM.h>

void setup()
{
Serial.begin(9600);
EEPROM.begin(4095);
String value = "";
EEPROM.get( 0, value );
delay(200);
Serial.println("Value after reboot is: " + value);

Serial.println("Write new EEPROM-value");

value = "HelloWorld";
EEPROM.put( 0, value );
delay(200);
EEPROM.commit();

value = "";
EEPROM.get( 0, value );
delay(200);
Serial.println("Value after writing, without reboot is: " + value);
}

void loop()
{

}

Here is the result of the output:

Value after reboot is:
Write new EEPROM-value
Value after writing, without reboot is: HelloWorld
⸮⸮⸮⸮⸮D⸮⸮⸮$⸮⸮⸮Value after reboot is:
Write new EEPROM-value
Value after writing, without reboot is: HelloWorld

you can't save String to EEPROM. the String object is only a 'manager' for a dynamically allocated char array

Thank you for the reply. I wonder why it is working without a reboot then? :astonished:

When I get you right, you recommend to save the char array in the EEPROM instead?
I will try to use myString.toCharArray(buf, len) to convert the string when I come home.

Thanks again.

gortax724:
Thank you for the reply. I wonder why it is working without a reboot then? :astonished:

because the char array is still in memory