I am putting an esp32 to sleep periodically while employing a real time clock per the guide
https://randomnerdtutorials.com/guide-for-real-time-clock-rtc-module-with-arduino-ds1307-and-ds3231/
The clock is keeping time, however, it resets after each sleep period. How to solve this?
Hi.
Does your RTC have a battery?
Do you have some sort of code to adjust the time? Remember that every time the ESP wakes up, it will run the code from the start. If you have some lines to adjust or reset the timer, they will run every time after the ESP wakes up.
Regards,
Sara
Yes, it has a battery which I confirmed to be charged. I actually have two RTCs that exhibit the same behavior.
I am using the RNT RTC guide code. The reset/time calibration statement is commented out after it is calibrated.
I am using the RNT deep sleep code from Project 4, modified w/o LoRa and using MQTT.
When you say the timer resets, what happens exactly? What do you get in the Serial Monitor?
It keeps updating the time as expected, but once it sleeps and wakes up, it resets to the reset time. For example,
Time(s) = 11
9:57:11 25/10/22 Day of week: Tuesday
Connecting to xxxx
.WiFi connected
IP address: 10.0.0.xx
Soil_station.cpp
Connected to MQTT Broker!
RSSI: -65 dB
soilMoisture: 1184
Moisture: 27.00 %
Temperature: 72.61 *F
Temperature sent!
Moisture sent!
Time(s) = 14
9:57:14 25/10/22 Day of week: Tuesday
Connecting to xxx
.WiFi connected
IP address: 10.0.0.xx
Soil_station.cpp
Connected to MQTT Broker!
RSSI: -64 dB
soilMoisture: 1191
Moisture: 26.00 %
Temperature: 72.61 *F
Temperature sent!
Moisture sent!
Time(s) = 18
9:57:18 25/10/22 Day of week: Tuesday
Connecting to xx
Then after it sleeps –
Time(s) = 44
9:57:44 25/10/22 Day of week: Tuesday
Connecting to xxx
.WiFi connected
IP address: 10.0.0.xx
Soil_station.cpp
Connected to MQTT Broker!
RSSI: -64 dB
soilMoisture: 1178
Moisture: 29.00 %
Temperature: 72.61 *F
Temperature sent!
Moisture sent!
DONE! Going to sleep now.
⸮M⸮\⸮bά⸮$g⸮Time(s) = 0
9:57:00 25/10/22 Day of week: Tuesday
Connecting to xxx
.WiFi connected
IP address: 10.0.0.xx
Soil_station.cpp
Can you share your code? Or the snippets of code that deal with time and deep sleep?
To share a code use pastebin or github.
Regards,
Sara
Ok thanks. Here it is. The code uses the esp32 Project 4 w/o LoRa, but with RPi broker/subscriber to send MQTT from esp32 with temp/moisture topics. But I want to additionally and periodically save data to a SD Card, It would sleep then wake at a certain time, open the file and send mqtt to RPi. The code is not finished yet, so now just trying to sort out the clock part.
https://pastebin.com/r54cBJY6
Hi again.
You pasted the code in private. It’s not in the public domain.
Make sure you enable access to the link so that I can check the code.
Regards,
Sara
Hi.
After a quick search, I found this: https://forum.arduino.cc/t/the-ds3231-rtc-module-does-not-retain-the-time-everytime-i-powered-off-or-reset/563465/4
Check if adding those lines solves the issue.
Regards,
Sara
Thanks very much. This solved the issue.
By the way, it came down to adding the following statement, which is missing in the code by J Boxall in the RNT RTC guide.
Wire.write(0b00011100); // write register bitmap, bit 7 is /EOSC