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);*
}
}