Hi, any help would be appreciated, thanks in advance.
Use case: Track the number of resets / reboots after a device is reflashed / deployed and be able to reset the value remotely. I am also looking to do the same with wifi connection drops.
I can solve the reset part using a cloud function but am not having success with the first requirement.
My challenge is with resetting the EEPROM value after reflashing the device as the EEPROM value appears to be retained even after a reflash. I can see that this might be useful under some use cases so my questions are:
- is this behaviour correct, ie EEPROM values are not cleared on a reflash?
- if the behaviour is correct is there a way to programmatically tell when setup is run for the first time after a reflash or is there a way to clear / set EEPROM addresses to zero when reflashing?
Code used to test:
// Simple EEPROM test script
// Photon, Build 0.4.7
// Test 1: reflash multiples times and EEPROM does not reset - ?
// Test 2: reboot / repower multiple times and 'reboots' increments - CORRECT
#include "application.h"
int addr = 1;
int reboots = 0;
uint8_t val = 0;
void setup() {
Particle.variable("reboots", &reboots, INT);
val = EEPROM.read(addr);
if (val > 250) {
val = 0;
} else {
val++;
}
Serial.print("val = ");
Serial.println(val);
EEPROM.update(addr, val);
reboots = val;
}
void loop() {
}
Thanks in advance