Help in the code

Elangovan's picture

Offline

Joined: Sep 19, 2018

Replies: 0
Help in the code
June 18, 2019 - 6:36pm

Hie, i am having problem in understanding some part of the code. 

RTC_DATA_ATTR static time_t last;       

RTC_DATA_ATTR static uint32_t bootcount;

What is RTC_DATA_ATTR mean here.? and why are we using it?

 

Abhiemanyu Pandit's picture

Offline

Joined: Jan 21, 2019

Replies: 37
Help in the code
June 18, 2019 - 6:38pm

when you define a global variable with RTC_DATA_ATTR attribute, the variable will be placed into RTC_SLOW_MEM memory. So the structure declared as RTC_DATA_ATTR and copy the dynamic memory to this structure before a deep sleep helps recovering this into dynamic memory after wake up. In simple words we are saving the time in static memory from dynamic memory to recover it again after a deep sleep. Here the two variables are defined. The ‘last’ is used to get the last time when the ESP32 went to deep sleep and bootcount is used count number of resets.

I would suggest to post  the complete code and then we can clear a bit more.