How ESP32 keeps the time.localtime() without battery?
How ESP32 keeps the time.localtime() without battery?
Hello Team,
I need help to understand how the micropython OS, for the ESP32SPI, can keep the date&time, even without power.
Let me explain:
In our code, we update the date&time using the ntp.settime() via Wi-Fi. No issues here. The 'problem' comes when I unpower the board, 30 min, and once I turn it on, without let it execute the main.py, I enter in the REPL, and after execute time.localtime(), the date&time are sync. How it's possible?
What I expect is to have the same date, but with the time delayed 30 min. There is some kind of 'hidden' code in micropython that it executes ntp.settime() at boot?
Thanks.
I need help to understand how the micropython OS, for the ESP32SPI, can keep the date&time, even without power.
Let me explain:
In our code, we update the date&time using the ntp.settime() via Wi-Fi. No issues here. The 'problem' comes when I unpower the board, 30 min, and once I turn it on, without let it execute the main.py, I enter in the REPL, and after execute time.localtime(), the date&time are sync. How it's possible?
What I expect is to have the same date, but with the time delayed 30 min. There is some kind of 'hidden' code in micropython that it executes ntp.settime() at boot?
Thanks.
Re: How ESP32 keeps the time.localtime() without battery?
Without any power the time/date information should be totally gone, not even delayed. So there must be code that updates date & time. Maybe not in main.py, maybe in boot.py. Are you sure that there is no supply for the clock connected, like a coin cell?
Re: How ESP32 keeps the time.localtime() without battery?
How do you
rshell?I enter in the REPL
Re: How ESP32 keeps the time.localtime() without battery?
As davef hinted, using rshell will attempt to set the clock from your local computer
Re: How ESP32 keeps the time.localtime() without battery?
I used to have similar application on my Raspberry Pi and found the OS syncs the time every now and then as long as it has the internet connection. I remember the OS saves that sync time. If I power down the RPi, remove the Ethernet cable, then re-power maybe 10min later, the time is off. Once I reconnect the Ethernet, it corrects the time. I can't remember whether it syncs every minute or 2 min. I do remember it was in low number of minutes.
Re: How ESP32 keeps the time.localtime() without battery?
The discussion is about the RPi Pico, which foes not have an OS or Ethernet port. But the other comments ate right. PC programs like rshell or Thonny set the time when the device gets connected.
Re: How ESP32 keeps the time.localtime() without battery?
We use Thonny IDE. The boot.py is empty, and we rename the main.py to main1.py, also, once we power on the board with the ESP32-WROVER-E, we click "Stop/restart" (stop icon) button in order to enter to REPL without executing the main program. The board is not connected to Wi-Fi. (We powered off the AP)
After that, the we do:
Code: Select all
import time
time.localtime()
Re: How ESP32 keeps the time.localtime() without battery?
Really? Thonny IDE is using rshell? in its "Shell window"? If this is true, this is really dangerous... because how can you test if the ntp.settime() really works? only becaus it doesn't return an exception?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: How ESP32 keeps the time.localtime() without battery?
With a print statement. Or by deliberately miss-setting the time before the call to ntptime.how can you test if the ntp.settime() really works?
I don't know about Thonny, but rshell sets the time to enable rsync to work correctly.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.