Hi,
We are using EEPROM to save values over power off.
However, after a firmware update, all data is lost.
We are using a struct to save stuff:
struct {
char mode; // g=growing, d=dryimg
int dayCounter; // counting days the grow or dry was active. Starting from 1
bool isDay; // true if the light is on
int minutesInPhotoperiod; // how long has the system been in current photoperiod? E.g. 31 minutes in NIGHT
int dayDuration; // how long is the light on?
bool fanAutoMode; // 1 for auto, 0 for manual
float fanSpeed; // 0-100%
char tempUnit; // F or C
bool wifiStatus; // 1=on, 0=off
} eeprom;
eeprom.mode = 'g';
eeprom.dayCounter = -1;
eeprom.isDay = true;
eeprom.minutesInPhotoperiod = 0;
eeprom.dayDuration = 18 * 60;
eeprom.fanAutoMode = 1;
eeprom.fanSpeed = 30;
eeprom.tempUnit = 'F';
eeprom.wifiStatus = 1;
EEPROM.put(0, eeprom);
Now we added more features and need to save more stuff in EEPROM.
At first, I added more values to the struct:
struct {
char mode; // g=growing, d=dryimg
int dayCounter; // counting days the grow or dry was active. Starting from 1
bool isDay; // true if the light is on
int minutesInPhotoperiod; // how long has the system been in current photoperiod? E.g. 31 minutes in NIGHT
int dayDuration; // how long is the light on?
bool fanAutoMode; // 1 for auto, 0 for manual
float fanSpeed; // 0-100%
char tempUnit; // F or C
bool wifiStatus; // 1=on, 0=off
uint8_t version;
float targetTemperature;
float targetHumidity;
uint8_t fanSpeedMin;
uint8_t fanSpeedMax;
uint8_t ledBrightnessMax;
} eeprom;
But now, on first start after Software-Update, the system could not get() the struct anymore ... likely because it was changed.
That's what the documentation says here:
(..) Use the same type of object you used in the
putcall.
To solve this problem, I put new values into a second struct:
struct {
char mode; // g=growing, d=dryimg
int dayCounter; // counting days the grow or dry was active. Starting from 1
bool isDay; // true if the light is on
int minutesInPhotoperiod; // how long has the system been in current photoperiod? E.g. 31 minutes in NIGHT
int dayDuration; // how long is the light on?
bool fanAutoMode; // 1 for auto, 0 for manual
float fanSpeed; // 0-100%
char tempUnit; // F or C
bool wifiStatus; // 1=on, 0=off
} eeprom;
struct {
uint8_t version;
float targetTemperature;
float targetHumidity;
uint8_t fanSpeedMin;
uint8_t fanSpeedMax;
uint8_t ledBrightnessMax;
} eeprom2;
EEPROM.put(0, eeprom);
EEPROM.put(sizeof(eeprom), eeprom2);
and I retrieve them like this:
EEPROM.get(0, eeprom);
EEPROM.get(sizeof(eeprom), eeprom2);
But this still doesn't work.
After a firmware update, the system forgets all the values.
Can someone see a problem with my approach?
The full code can be seen here.
Thanks and kind regards