What do I need to do to keep the time of the real time clock using a Panda II with the Connect shield. the latter has a super cap. But even without disconnecting the USB power I loose the time after each restart / deploy. Why?
should do the trick. Of course, if the RTC has never been set, you’ll have to add some logic to test for that.
[edit] Also, the code you posted is out of order. It is not clear what your dateTime variable is set to before you use it. Not sure if you even need the first line. You should run the second line only after you have confirmed the NTP call worked. If I remember right (dubious assertion ;)) Nicolas3’s NTP function also sets the RTC, but best to check.
Essentially, it looks like you are setting the RTC from the System DateTime, which always initializes to 0 when you deploy/restart. This negates anything the NTP function did to set the RTC (if it even does) previous to the restart.
Debug.Print("real time clock before NTPTime : " + RealTimeClock.GetTime().ToString());
NTPTime("0.nl.pool.ntp.org", 60);
Debug.Print("real time clock after NTPTime : " + RealTimeClock.GetTime().ToString());
did the trick: the real time clock keeps the time, only the system time has changed.
Now I have to update the system time from the RTC and I should be done.
@ ransomhall
from the NTP example I only posted the part to show that I set the RTC at least once.