I’m attempting to dive into saving some of my configuration variables into EEPROM a couple of short power outages made me realize I need to store some of this stuff so it reboots with the right settings. However, I cannot seem to get it to behave as expected.I’ll post the relevant sections of code. I’m trying to read the data in my setup function but I even made a particle function that should read the data on demand for troubleshooting purposes and I cant seem to work either. I would input my desired settings from the particle functions but on boot it would all be back to 0’s on daily run times and unknown for my chlormodetext and acidmodetext particle variables. Running my particle function to try and manually read the EEPROM doesn’t change he values either. What am I doing wrong?
// I dont think this is necessarily relevant but I put it here in case any of these settings affect eeprom
STARTUP(WiFi.selectAntenna(ANT_EXTERNAL)); // Use external antenna
SYSTEM_MODE(SEMI_AUTOMATIC); // take control of the wifi behavior to avoid cloud bogging down local functions
SYSTEM_THREAD(ENABLED); // enable so loop and setup run immediately as well as allows wait for to work properly for the timeout of wifi
// declared relevant variables
int Cdailyruntime = 0;
int Adailyruntime = 0;
int acidmode = 0; // variable to control acid pump mode off = 0 time = 1 or auto =2
String acidmodetext = "unknown"; //acid mode textual version
int chlormode = 0; // variable to control chlorine pump mode off = 0 time = 1 or auto =2
String chlormodetext = "unknown"; //chlorine mode textual version
// EEPROM address locations should be plenty far apart
int cdaddress = 0;
int adaddress = 10;
int amodeaddress = 20;
int cmodeaddress = 30;
void setup() {
EEPROM.get(cmodeaddress, chlormode);
if (chlormode == 0){
chlormodetext == "off";
}
if (chlormode == 1){
chlormodetext == "time";
}
if (chlormode == 2){
chlormodetext == "auto";
}
EEPROM.get(amodeaddress, acidmode);
if (acidmode == 0){
acidmodetext == "off";
}
if (acidmode == 1){
acidmodetext == "time";
}
if (acidmode == 2){
acidmodetext == "auto";
}
EEPROM.get(adaddress, Adailyruntime);
EEPROM.get(cdaddress, Cdailyruntime);
//particle functions
Particle.function("ChlorMode", chlormodefunc);
Particle.function("AcidMode", acidmodefunc);
Particle.function("AcidDaily", Adaily);
Particle.function("ChlorDaily", Cdaily);
Particle.function("eepromread", eeprom);
// and particle variables
Particle.variable("AcidMode", acidmodetext);
Particle.variable("ChlorMode", chlormodetext);
Particle.variable("ChlorDaily", Cdailyruntime);
Particle.variable("AcidDaily", Adailyruntime);
}
void loop(){
}
// turn acid pump modes from the cloud
int acidmodefunc(String command){
if (command == "0"){
acidmode = 0;
acidmodetext = "off";
EEPROM.put(amodeaddress, acidmode);
return 0;
}
else if (command == "1"){
acidmode = 1;
acidmodetext = "time";
EEPROM.put(amodeaddress, acidmode);
return 1;
}
else if (command == "2"){
acidmode = 2;
acidmodetext = "auto";
EEPROM.put(amodeaddress, acidmode);
return 2;
}
else {
acidmode = 0;
acidmodetext = "off";
EEPROM.put(amodeaddress, acidmode);
return 0;
}
}
// turn chlorine pump modes from the cloud
int chlormodefunc(String command){
if (command == "0"){
chlormode = 0;
chlormodetext = "off";
EEPROM.put(cmodeaddress, chlormode);
return 0;
}
else if (command == "1"){
chlormode = 1;
chlormodetext = "time";
EEPROM.put(cmodeaddress, chlormode);
return 1;
}
else if (command == "2"){
acidmode = 2;
chlormodetext = "auto";
EEPROM.put(cmodeaddress, chlormode);
return 2;
}
else {
acidmode = 0;
chlormodetext = "off";
EEPROM.put(cmodeaddress, chlormode);
return 0;
}
}
// cloud trigger for chlorine daily change
int Cdaily(String command){
Cdailyruntime = atoi (command);
EEPROM.put(cdaddress, Cdailyruntime);
return Cdailyruntime;
}
// cloud trigger for acid daily change
int Adaily(String command){
Adailyruntime = atoi (command);
EEPROM.put(adaddress, Adailyruntime);
return Adailyruntime;
}
int eeprom(String command){
if(command == 0){
EEPROM.get(cmodeaddress, chlormode);
if (chlormode == 0){
chlormodetext == "off";
}
if (chlormode == 1){
chlormodetext == "time";
}
if (chlormode == 2){
chlormodetext == "auto";
}
EEPROM.get(amodeaddress, acidmode);
if (acidmode == 0){
acidmodetext == "off";
}
if (acidmode == 1){
acidmodetext == "time";
}
if (acidmode == 2){
acidmodetext == "auto";
}
EEPROM.get(adaddress, Adailyruntime);
EEPROM.get(cdaddress, Cdailyruntime);
}
}