I found a method for storing variables during sleep mode on ESP 8266 by searching on the web and found ESP.rtcUserMemoryRead() or write(). And it is coming out with strange results. The code that I have used is below.
The value of bootCount always starts at 3289620196. I can compensate for this, but am I missing something? If I Serial.print bootCamp prior to ESP.rtcUserMemoryRead(), I get 0.
Is there something I need to do in the preprocessor section to set the rtcUserMemory to zero?
uint32_t bootCount=0;
/////////////////////////////////////////////////////////////////////
void setup() {
// Serial port for debugging purposes
Serial.begin(74880);
while(!Serial) { }
if(!ESP.rtcUserMemoryRead(0, &bootCount, sizeof(bootCount))) {
Serial.println("RTC read failed!");
while(1)
yield();
}
delay(2000);
Serial.println();
Serial.print("bootCount = ");
Serial.println(bootCount);
Serial.println();
Serial.print("Actual bootCount = ");
Serial.println(bootCount-3289620196);
Serial.println();
bootCount++;
if(!ESP.rtcUserMemoryWrite(0, &bootCount, sizeof(bootCount))) {
Serial.println("RTC write failed!");
while(1)
yield();
}
ESP.deepSleep(30e6);
}
void loop() {
}