I'v been stuck on this for days now and reached the point where I ordered new modules while I get on the forums. I'm trying to use EEPROM on the ESP8266 to store the info that i might change once i close my project up but am having problems committing the data to EEPROM for recovery during a power cycle. The code runs on an Arduino uno clone but once i try running it on the ESP when I power cycle, i get a stack dump. I vaguely get that the ESP doesn't have EEPROM built in but is simulated. the code that I'm including is using the ESP_EEPROM.h lib since just using the standard EEPROM.h lib didn't highlight "commit" in orange which I found suspect.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#include <ESP_EEPROM.h>
String ssid = "";
String pass = "";
String city = "";
String country = "";
int actionCode = 0;
void setup() {
EEPROM.begin(512);
Serial.begin(9600);
Serial.println();
Serial.println("Start!");
while(!Serial.available());
actionCode = Serial.parseInt();
if(actionCode == 100){
enterWifiStuff();
}
int wifiLen = EEPROM.read(0);
char wifiGet[wifiLen];
for(int i = 0; i < wifiLen; i++){
wifiGet[i] =char(EEPROM.read(i + 1));
}
Serial.print(wifiGet);
parseCharArray(wifiGet);
Serial.println();
Serial.print("ssid: ");
Serial.println(ssid);
Serial.print("password: ");
Serial.println(pass);
Serial.print("city: ");
Serial.println(city);
Serial.print("country: ");
Serial.println(country);
Serial.println("");
WiFi.begin(ssid,pass);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi Connected");
printWiFiStatus();
Serial.print("xxCONECTEDxx");
actionCode = 0;
}
void loop(){
int actionCode = Serial.parseInt();
if(actionCode == 100){
Serial.print("xxCONECTEDxx");
}
}
void printWiFiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
void parseCharArray(char string[]){
int count1 = 0;
int count2 = 0;
int startWord = 0;
while(count1 < 4){
if(string[count2] == 'x' && string[count2 + 1] == 'x'){
count2 += 2;
count1++;
startWord = count2;
}
else{
if(count1 == 0){
ssid += string[count2];
}
else{
if(count1 == 1){
pass += string[count2];
}
else{
if(count1 == 2){
city += string[count2];
}
else{
country += string[count2];
}
}
}
count2++;
}
}
}
void enterWifiStuff(){
Serial.println();
delay(1000);
while(Serial. read() >= 0) ;
Serial.print("SSID: ");
while(!Serial.available()){}
String ssid = Serial.readString();
int lens = ssid.length();
Serial.print(lens);
Serial.println(ssid);
Serial.print("Password: ");
while(!Serial.available()){}
String pass = Serial.readString();
Serial.println(pass);
Serial.print("City: ");
while(!Serial.available()){}
String city = Serial.readString();
Serial.println(city);
Serial.print("Country code: ");
while(!Serial.available()){}
String country = Serial.readString();
Serial.println(country);
String msg = ssid + 'x' + 'x' + pass + 'x' + 'x' + city + 'x' + 'x' + country + 'x' + 'x';
ssid = "";
pass = "";
city = "";
country = "";
int len = msg.length();
Serial.println(len);
Serial.print("THIS IS MY DUMP");
Serial.println(msg);
int wifiLen = msg.length() + 1;
char wifiPut[wifiLen];
msg.toCharArray(wifiPut, wifiLen);
EEPROM.write(0, wifiLen);
for(int i = 0; i < wifiLen; i++){
EEPROM.write(i + 1, wifiPut[i]);
}
boolean ok = EEPROM.commit();
Serial.println((ok) ? "Commit OK" : "Commit failed");
}
this is the serial output
Start!
SSID: 5funny
Password: stuff
City: in
Country code: us
22
THIS IS MY DUMPfunnyxxstuffxxinxxusxx
Commit failed //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<this line
funnyxxstuffxxinxxusxx
ssid: funny
password: stuff
city: in
country: us
connecting........0⸮~⸮4⸮!⸮⸮⸮⸮OAqr⸮⸮
Start!
⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮?⸮⸮⸮?
Exception (3):
epc1=0x40201134 epc2=0x00000000 epc3=0x00000000 excvaddr=0x40000000 depc=0x00000000
>>>stack>>>
ctx: cont
sp: 3ffffdc0 end: 3fffffc0 offset: 01a0
3fffff60: 00000000 3fffff80 3ffee438 3fffff80
3fffff70: 00000000 3fffff80 3ffee438 40201458
3fffff80: feefeffe feefeffe feefeffe feefeffe
3fffff90: feefeffe feefeffe feefeffe 3ffee4b0
3fffffa0: 3fffdad0 00000000 3ffee470 40203034
3fffffb0: feefeffe feefeffe 3ffe84e8 40100be1
<<<stack<<<
bBʦ⸮!⸮⸮1⸮1⸮⸮
Start!
I snagged a bit of code from the ESP_EEPROM.h examples. i tried running those as well and it gives me the same result of "commit failed".
just to be clear, the first time the code is run I enter 100 to get to the input portion. the second time after the power cycle i enter 200 (or any number other than 100) to skip the input. this is when it reads garbage from EEPROM.
