What is better way to store some data after deep sleep?

hyunwoo
Posts: 15
Joined: Tue May 04, 2021 6:54 am

What is better way to store some data after deep sleep?

Postby hyunwoo » Fri Jul 30, 2021 7:21 am

Hi,

I'm in low power device project. That device check status periodic and send it data to server.
For reduce power consumption, my ESP32 is always go to deep sleep after finish all works.

But we need to store some data that before deep sleep, like 'is_first_boot'. This variable checks 'booting' or 'waking up' at start of my code. It means the changing value of data is not often.
So I used 'RTC_DATA_ATTR' keyword. but I still have a doubt of perfomance.

What is better?
1. Store to NVS and Restore.
2. Use RTC memory.
3. Anything else?

Thanks.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: What is better way to store some data after deep sleep?

Postby ESP_Sprite » Fri Jul 30, 2021 9:21 am

What do you mean, 'doubt of performance'? What performance are you worried about?

hyunwoo
Posts: 15
Joined: Tue May 04, 2021 6:54 am

Re: What is better way to store some data after deep sleep?

Postby hyunwoo » Mon Aug 02, 2021 6:17 am

Hmm... I just want to know what is better way!

Using NVS or RTC memory.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: What is better way to store some data after deep sleep?

Postby ESP_Sprite » Mon Aug 02, 2021 8:30 am

There is no such thing as 'the (universally) better' way; asking for that is like asking if a screwdriver or a hammer is better; it depends on if you have screws or nails on hand. In general, RTC memory is better as storing/reading data is faster but a loss of power loses everything; NVS doesn't have that downside but is slower to use and depending on the amount of writes you do, you may need to keep flash write cycles in mind. Which one is 'better' depends on what you need to do with it.

hyunwoo
Posts: 15
Joined: Tue May 04, 2021 6:54 am

Re: What is better way to store some data after deep sleep?

Postby hyunwoo » Wed Sep 08, 2021 10:43 am

Thank you for kindly response.

I decide to use both of them.
And here is flow of my source code. Please advice to me.
  • 1. Check the device is reset. (check some value that restored in slow RTC memory is 0)
    • a. If device is reset, load value to slow RTC memory from NVS.
    • b. If device is just waken up, do noting.
  • 2. Perform jobs with slow RTC data.
  • 3. Check input about changing configuration data.
    • a. If input data exists, apply that to NVS and RTC memory.
  • 4. Clean before sleep.
  • 5. Sleep and go to 1.
Is this better than use only one of them(NVS, RTC memory)?
Is there some best way to store configuration data?

Thank you!

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: What is better way to store some data after deep sleep?

Postby ESP_Sprite » Thu Sep 09, 2021 1:28 am

I think you're prematurely optimizing, to be honest... if you store your data to NVS as often as you do it to RTC mem, it simplifies your code to simply rip out the RTC mem path and only use NVS.

hyunwoo
Posts: 15
Joined: Tue May 04, 2021 6:54 am

Re: What is better way to store some data after deep sleep?

Postby hyunwoo » Fri Sep 10, 2021 4:02 am

I think my device won't be reset that often in normal scenario, because of using battery.
Even considering this, is it still a prematurely optimization?

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: What is better way to store some data after deep sleep?

Postby ESP_Sprite » Sat Sep 11, 2021 2:50 am

hyunwoo wrote:
Fri Sep 10, 2021 4:02 am
I think my device won't be reset that often in normal scenario, because of using battery.
Even considering this, is it still a prematurely optimization?
It depends. If you write your NVS as often as you write RTC memory, yes; there's no need to write it to RTC mem as you can get the data from NVS just as easily. It might be useful for flash life and maybe power use to update NVS less often than RTC and have both paths, but I'd run the numbers on that before making a decision. (To be honest: Or you can just do whatever you feel comfortable with, it'll work even if it's more complex.)

Who is online

Users browsing this forum: Baidu [Spider], HighVoltage and 145 guests