ESP8266 RTC Memory

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() {
 
  
}

introduce a checksum/CRC like in the IDE Example:

if the checksum doesn't fit, init your counter to 0

Thanks for that. Unfortunateley, it's a bit beyond me at present. I have however added a few lines which check that the values are within expected parameters and set it to zero if not.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.