I'm trying to store a struct of integers into the emulated eeprom on an esp8266. after i write the struct to address and comment out the write code i try to read a value after reflashing but the value is not what i stored?
#include <EEPROM.h>
int addr = 0;
struct {
int Light1;
int Light2;
int Light3;
int Light4;
int Light5;
int Light6;
int Light7;
int Light8;
int Light9;
} _EEPROM;
void setup()
{
Serial.begin(115200);
EEPROM.begin(512); //Initialize EEPROM
EEPROM.get(addr,_EEPROM);
//un comment below to write data
// write to EEPROM.
// _EEPROM.Light1 = 999;
// EEPROM.write(addr, _EEPROM.Light1);
//EEPROM.commit(); //Store data to EEPROM
}
void loop()
{
Serial.println(_EEPROM.Light1);
}
NVM this is what i ended up with. replacing write with put solved the problem i think,
#include <EEPROM.h>
int addr = 0;
struct {
int array[9] = {800, 800, 800, 800, 800, 800, 800, 800, 800};
} _EEPROM;
void _writeEEPROM () {
EEPROM.put(addr, _EEPROM);
EEPROM.commit(); //Store data to EEPROM
}
void setup()
{
Serial.begin(115200);
EEPROM.begin(512); //Initialize EEPROM
EEPROM.get(addr, _EEPROM);
// _EEPROM.array[0] = 100;
// _EEPROM.array[1] = 200;
// _EEPROM.array[2] = 300;
// _EEPROM.array[3] = 400;
// _EEPROM.array[4] = 500;
// _EEPROM.array[5] = 600;
// _EEPROM.array[6] = 700;
// _EEPROM.array[7] = 800;
// _EEPROM.array[8] = 900;
// _writeEEPROM ();
}
void loop()
{
Serial.println(_EEPROM.array[0]);
Serial.println(_EEPROM.array[1]);
Serial.println(_EEPROM.array[2]);
Serial.println(_EEPROM.array[3]);
Serial.println(_EEPROM.array[4]);
Serial.println(_EEPROM.array[5]);
Serial.println(_EEPROM.array[6]);
Serial.println(_EEPROM.array[7]);
Serial.println(_EEPROM.array[8]);
delay(1000);
}