As the title says... Chat on...

User avatar
By JOHN_T
#64995 Hoping someone can explain what I am doing wrong...

I believe the RTC should maintain reasonable time during deep sleep cycles but I have noticed weird RTC behaviour when I "manually" reset the ESP8266 during a rtctime.dsleep sleep period. If the ESP8266 is sleeping and I manually reset it using a very brief signal on the RESET pin, the RTC time now jumps forward by the same amount as the number of microseconds used in the rtctime.dsleep command.

The code below pasted into init.lua will reproduce the problem. The code will print the date/time, wait for 10 seconds and sleep for 3600 seconds. If the ESP has just entered the dsleep state and I trigger a hardware RESET, the time will have jumped forward precisely 3600 seconds... and if I wait for dsleep again and trigger another RESET, the time is now 3600+3600 seconds ahead of where it should be after this second manual RESET. If I change the "SleepSeconds" variable to 600, the time jumps forward precisely 600 seconds each time I trigger the hardware RESET.

If I sit on my hands and don't trigger a manual RESET, and just let dsleep reset the ESP after the required sleep period, the time is kept perfectly OK. I would have hoped the RTC should keep its own time independent of the rtctime.dsleep period, or external RESET signal. Could someone let me know if this is expected behaviour?

Thanks,
John.




--Using firmware: powered by Lua 5.1.4 on SDK 2.0.0
--initialise the RTC if needed (ie. power lost)
if rtctime.get()<123456 then
print("Initialising RTC")
rtctime.set(123456,0)
else
print("RTC:"..rtctime.get())
end

--print the time...
tm = rtctime.epoch2cal(rtctime.get())
print(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]))

--configure sleep timer
WakeSeconds=10
SleepSeconds=3600
--schedule ESP to sleep soon...
print("Sleeping in "..WakeSeconds)
tmr.alarm(0,WakeSeconds*1000,tmr.ALARM_SINGLE,function()
--turn off WiFi modem, so its off on next wakeup
wifi.sleeptype(wifi.MODEM_SLEEP)

print(SleepSeconds.." Sleep...")
--schedule wakeup via RTC
rtctime.dsleep(SleepSeconds*1000*1000,4)
end
)