EEPROM and error handler and RTC save time issue

maher1personal
Posts: 2
Joined: Sat Sep 23, 2023 8:40 am

EEPROM and error handler and RTC save time issue

Postby maher1personal » Sat Sep 23, 2023 9:08 am

Hello everyone
i am a bit new to ESP32, and i need your help about an issue i am facing

i am using <ESP32Time.h> library to use 24h clock to make schedual timer
the real current time will be set manually by user interface through LCD.
the project won't be connected to wifi internet connection for now.

i need a way to call a function that i call saveTime2EEPROM only if somethiung wrong happened like pwoer lose for a second or reset button is pressed or if WDT reset occured or any other reason that will make the current minutes and hours variable data to be lost

i could use that approach on ATMEGA32 for example, but i can't find a way for ESP32

i though about making a call to that function everytime the minutes value changes but that will kill the flash so quick

any ideas?
thank you

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: EEPROM and error handler and RTC save time issue

Postby lbernstone » Sat Sep 23, 2023 6:37 pm

If the power is lost, the device goes offline in about a millisecond. There would not be time to write anything to flash. If you want persistent time, get an external RTC and a battery, just like you would on a computer. Instead of trying to keep time through watchdog failures, fix what is blocking.
The device does keep time in its RTC through deep sleep. https://github.com/lbernstone/NTP_sleep ... _sleep.ino.
Writing one sector to flash every minute will not kill the flash. The nvs has wear levelling, so if you increase the size of the nvs partition, you get more durable "EEPROM". While rated for 100000 cycles per cell, they are actually more durable than this. But, how do you know how much time has passed while the system was down?

maher1personal
Posts: 2
Joined: Sat Sep 23, 2023 8:40 am

Re: EEPROM and error handler and RTC save time issue

Postby maher1personal » Sun Sep 24, 2023 6:37 am

lbernstone wrote:
Sat Sep 23, 2023 6:37 pm
If the power is lost, the device goes offline in about a millisecond. There would not be time to write anything to flash. If you want persistent time, get an external RTC and a battery, just like you would on a computer. Instead of trying to keep time through watchdog failures, fix what is blocking.
The device does keep time in its RTC through deep sleep. https://github.com/lbernstone/NTP_sleep ... _sleep.ino.
Writing one sector to flash every minute will not kill the flash. The nvs has wear levelling, so if you increase the size of the nvs partition, you get more durable "EEPROM". While rated for 100000 cycles per cell, they are actually more durable than this. But, how do you know how much time has passed while the system was down?
hey,
thank you for your replay,
i am not placing to use any external modules, i just wanna use the internal RTC clock of the ESP,
about keeping time passed while the system is off, the whole idea is based to serve a second to 5 sec power off accidental.
NTP servers might be added, the situation of saving time will be just for emergency issue. otherwise, the system should be resetted with real time or pull the real time from NTP server

Who is online

Users browsing this forum: No registered users and 63 guests