I have need to take values from a web served form and commit them to EEPROM for later use. As I am making a heater timer/controller and want to store setpoints and switch times using web server, via sinric, or some control manually. The web form is handled correctly, stores the variables in RAM OK as it then reads them back into the served webpage. As last part of that I call a write value sub routine to pass all the values into flash. So this works for 28 bytes of time value, string name, and various other parameters, but one of the setpoints refuses to store! I've called out begin, commit, etc, and added a delay post commit and read as suggested elsewhere, but whilst everything else stores and reads back, this one value (Set1) doesn't, any ideas? I've tried different registers, clearing the flash, changing the name, but this byte just will not store correctly, yet variable reads fine elsewhere. (The setpoint is stored as 255 steps between 10 and 35°C and operated on elsewhere).
Read Routine:
void readValues() {
for (int k = 0; k <= 6; k++) {
EEPROM.get(k, onHour[k] ); //0 - 6 (EEPROM Address) Sunday to Saturday
EEPROM.get(k + 7, onMin[k] ); //7 - 13
EEPROM.get(k + 15, offHour[k] ); //14 - 20
EEPROM.get(k + 22, offMin[k] ); //21 - 28
}
byte j;
MyHostName = "";
EEPROM.get(40, j); //length of string
for (int l = 0; l < j; l++) { //get the string as individual characters and concatanate
char k;
EEPROM.get(41 + l, k);
MyHostName = MyHostName + k;
}
EEPROM.get(30, Set1);
EEPROM.get(31, Set2);
EEPROM.get(32, Set3);
EEPROM.get(60, Kp);
EEPROM.get(61, Ki);
EEPROM.get(62, Kd);
delay(500);
}
Write Routine:
bool writeValues() {
for (int i = 0; i <= 6; i++) {
EEPROM.put(i, onHour[i]); //0 - 6 (EEPROM Address) Sunday to Saturday
EEPROM.put(i + 7, onMin[i]); //7 - 13
EEPROM.put(i + 15, offHour[i]); //14 - 20
EEPROM.put(i + 22, offMin[i]); //21 - 28
}
EEPROM.put(30, Set1 );
EEPROM.put(31, Set2 );
EEPROM.put(32, Set3 );
byte varLen = (MyHostName).length();
EEPROM.put(40, varLen); //put the variable length to EEPROM
char myName[16];
strcpy(myName, MyHostName.c_str());
EEPROM.put(41, myName); //put the Name to EEPROM
for (int i = 0 + varLen; i <= 16; i++) { //add ASCII blanks to remaining registers
EEPROM.put(i + 41 + varLen, 0x20);
}
EEPROM.put(60, Kp);
EEPROM.put(61, Ki);
EEPROM.put(62, Kd);
bool error = EEPROM.commit();
delay(200);
#ifdef serialActive
if (error) {
Serial.println("ERROR! EEPROM commit failed");
} else {
Serial.println("EEPROM successfully committed");
}
#endif
return error;
}