3

I am using esp-IDF library and esp32 for smart lighting. I want to maintain the state of the lights when power goes off as it can be written somewhere in NVS.

Such implementation is available for arduino boards. When I’m trying to do the same for esp32, there is no provision as of now.

My data size is very simple just 3 pins and their statuses.

I tested brownout detector using interruption but it was not quite helpful.

Can someone help me on this?

6
  • 3
    Just save the state every time you change it? I’m not sure I really understand the question...
    – jcaron
    May 3 '20 at 20:54
  • We can do that, but nvs has a limitation of 1,00,000 cycles. My point is, we will have the switch states when chip is running, why do we need to waste a cycle for each state change. Above option will write in NVS or eeprom only when power is going down by adding just bulk capacitors in our power source. We can limit nvs writes in this way.
    – Learner
    May 4 '20 at 11:00
  • 1
    This approach ideally will manage data 1,00,000 power cut happenings essentially rather changing state when user changes(~100 times a day)
    – Learner
    May 4 '20 at 11:03
  • 3
    The NVS library uses wear levelling. Or, if you have an RTC battery, you could save to RTC memory. If you really want to write when power goes down, you probably need something that monitors power before your capacitors, and large enough capacitors for the ESP32 to have time to write the data before it goes below its operating threshold. Have you tried adjusting CONFIG_ESP32_BROWNOUT_DET_LVL_SEL to the maximum value?
    – jcaron
    May 4 '20 at 15:02
  • 2
    Also note that since flash is slow, and the NVS library uses wear levelling, you most certainly want to write a single (short) value rather then each value to a separate NVS entry or a string. You probably also want to open the NVS storage in advance. You really want to have the least possible to do during in the brownout handler, as you may have very little time to do anything. Did you actually measure how long you have from power down to the capacitors getting below the minimum voltage for the ESP32?
    – jcaron
    May 4 '20 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.