#include <EEPROM.h>
// wifi takes up most at 64 bytes -> start reading at byte 65
#define HISTORY_ADDR 65 // Starting address for history in EEPROM
#define HISTORY_SIZE sizeof(History) // Size of each record
struct History {
int sys, dias, pulse;
};
History loadHistory() {
History his;
EEPROM.get(HISTORY_ADDR + HISTORY_SIZE, his);
return his;
}
void setHistory(History his) {
// Write data directly to EEPROM
EEPROM.put(HISTORY_ADDR + HISTORY_SIZE, his);
EEPROM.commit();
}
void setup() {
Serial.begin(115200);
EEPROM.begin(512);
History his = {123, 90, 60};
setHistory(his);
History hisMem;
hisMem = loadHistory();
Serial.printf("History loaded: %d, %d, %d", hisMem.sys, hisMem.dias, hisMem.pulse);
}
void loop() {
delay(10);
}