write and read char to/from EEPROM doesn´t work

Hey guys,

I´m new in this forum because I need your help.

I writing char´s to the EEPROM of a ESP8266.
If I read the data from the EEPROM before switching off the mc it works properly.
If I read the data after switching off I receive just rubbish.

What am I doing wrong?

I hope I´m in the right part of the forum, otherwise please apologize.

Thanks for your help.

Here my code:

#include <EEPROM.h>;

char mySSID[50];
char myPWD[50];
char myIP[50];
char cSSID[50];
char cPWD[50];
char cIP[50];
String sSSID;
String sPWD;
String sIP;
int i;

void getData(){
Serial.println("SSID eingeben...");
while(Serial.available() == 0){

}
sSSID = Serial.readString();

Serial.println("Passwort eingeben...");
while(Serial.available() == 0){

}
sPWD = Serial.readString();

Serial.println("IP eingeben...");
while(Serial.available() == 0){

}
sIP = Serial.readString();

for (i=0; i <= sSSID.length(); i++){
mySSID = sSSID*;*
* mySSID[i+1] = '\0';*
* }*
* for (i=0; i <= sPWD.length(); i++){*
myPWD = sPWD*;*
* myPWD[i+1] = '\0';*
* }*
* for (i=0; i <= sIP.length(); i++){*
myIP = sIP*;*
* myIP[i+1] = '\0';*
* }*
}
void writeEEPROM(){
* for(i=0; i<= sSSID.length(); i++){*
_ EEPROM.put(i, mySSID*);
}
EEPROM.put(i+1, '\0');
for(i=0; i<= sPWD.length(); i++){
EEPROM.put(i+60, myPWD);
}
EEPROM.put(i+61, '\0');
for(i=0; i<= sIP.length(); i++){
EEPROM.put(i+120, myIP);
}
EEPROM.put(i+121, '\0');
}
void readEEPROM(){
for(i=0; i<=50; i++){
cSSID = EEPROM.read(i);
if(cSSID == '\0'){
break;
}
}
for(i=0; i<=50; i++){
cPWD = EEPROM.read(i+60);
if(cPWD == '\0'){
break;
}
}
for(i=0; i<=50; i++){
cIP = EEPROM.read(i+120);
if(cIP == '\0'){
break;
}
}
}
void setup() {
Serial.begin(9600);
EEPROM.begin(200);
}*

void loop() {
while(!Serial){_

}
Serial.println("Wollen Sie neue Daten eingeben? (y/n)");
while (Serial.available() == 0){

}
if(Serial.readString()[0] == 'y'){
* getData();*
* writeEEPROM();*
}
else{
* Serial.println("Sollen die Daten nun angezeigt werden? (y/n)");*
* while(Serial.available() == 0){*

* }*
* if(Serial.readString()[0] == 'y'){*
* Serial.print("SSID: ");*
* Serial.println(mySSID);*
* Serial.print("Passwort: ");*
* Serial.println(myPWD);*
* Serial.print("IP: ");*
* Serial.println(myIP);*
* }*
}
Serial.println("Wollen Sie Daten aus dem EEPROM lesen? (y/n)");
while (Serial.available() == 0){

}
if(Serial.readString()[0] == 'y'){
* readEEPROM();*
* Serial.print("SSID: ");*
* Serial.println(cSSID);*
* Serial.print("Passwort: ");*
* Serial.println(cPWD);*
* Serial.print("IP: ");*
* Serial.println(cIP);*
}
}

Please use code tags when you post code or warning/error messages. To do this, click the </> button on the forum toolbar, then paste the text you want to be in the code tags. Finally, move the cursor out of the code tags before adding any additional text you don't want to be in the code tags. If your browser doesn't show the posting toolbar, then you can manually add the code tags like this:
[code]``[color=blue]// your code is here[/color]``[/code]

The reason for doing this is that, without code tags, the forum software can interpret parts of your code as markup (the italics in your code above for example), leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier for us to read your code and to copy it to the IDE or editor.

Using code tags and other important information is explained in the "How to use this forum" post. Please read it.

Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

Now to your problem. The ESP8266 EEPROM library works differently from the AVR one. I see you already learned that you need to call EEPROM.begin(), but you must have forgotten to read the part of the documentation that explains:
https://arduino-esp8266.readthedocs.io/en/2.5.2/libraries.html#eeprom

EEPROM.write does not write to flash immediately, instead you must call EEPROM.commit() whenever you wish to save changes to flash. EEPROM.end() will also commit, and will release the RAM copy of EEPROM contents.

Hey pert,

Thanks for your quick reply.
You saved my day

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per