How to have RTC time on soft reset

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
Post Reply
jcrfonera
Posts: 6
Joined: Tue Oct 27, 2015 6:11 pm

How to have RTC time on soft reset

Post by jcrfonera » Fri Dec 04, 2015 6:22 pm

Following the forum topic i use this code to init the wipy RTC:

import time
from machine import RTC
rtc = machine.RTC()
print (rtc.now())

#set RTC with NTP time only if hardware reset or Power on
if wlan.isconnected() and machine.reset_cause() != machine.SOFT_RESET:
import untplib
c=untplib.NTPClient()
resp=c.request('0.europe.pool.ntp.org', version=3, port=123)
rtc.init(time.localtime(time.time() + resp.offset))

#from Micropython
print ('Current TIME is ' ,time.localtime(),'\r\n')
#from Wipy RTC
T1= (rtc.now())
print (T1)
print ("Date is : ",T1[0],"/",T1[1],"/",T1[2])

following an soft reset the time is : (2015,1,1,0,0,0 ...... )

i do not understand why RTC is not valid if already initialized on power on or hard reset

@danicampora:
Please, I still awaiting a response on this topic:
if my program initiates a software reset and I'm out of wi-fi for a NTP request, time for my program becomes false,
and this is not correct for an embedded system!!
The clock, once initialized must remain valid if there is no power failure.
Could you explain why soft reset cause RTC wiht only correct year , but no valid hours,min,sec?

Post Reply