I would like to save my Circular Buffer in the RTC memory of my ESP32 when I use deep sleep. So I have initialized it with RTC_DATA_ATTR but when I go into Deep Sleep I lose the data I've saved. Is there a way to do this?

Here is my function:

RTC_DATA_ATTR CircularBuffer<Datas, 178> test_SensorsDatas;

void test_RTC_memory(){

    for(int i=1; i<=20; i++){

    for(int i=0; i<test_SensorsDatas.size(); i++){


Thank you very much! Ask me questions if something isn't clear ;)

EDIT: I tried something much simplier:

RTC_DATA_ATTR sensorsRecord newrecord{20, ID_sensor, ID_msg, epochUnion, ValueUnion, intValue, 30};
RTC_DATA_ATTR CircularBuffer<sensorsRecord, 50> test_SensorsDatas;

void test_RTC_memory2(){
    Serial.println("buffer size: " + String(test_SensorsDatas.size()));

But still not working, the ID_msg is incrementing well but not the buffer size even if I push a new value at every wake up.
Any suggestion?

  • I would guess the object is stored in RTC memory but the memory used by the object isn't. You'll need to apply the RTC_DATA_ATTR to the array inside the object, not the object itself.
    – Majenko
    Commented Dec 28, 2021 at 13:47
  • Yes tried to define the data using RTC_DATA_ATTR outside of the function and after I push it in the Circular Buffer, I was unable to find it after the deep sleep...
    – EMall
    Commented Dec 28, 2021 at 14:18
  • first figure out what is really going on. test by storing a number- char, int, short etc. your simpler test case was a good thought but go even simpler.
    – Abel
    Commented Dec 30, 2021 at 13:05


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.