I a m using NTPClient to get unix epoch and setting ( setting real time clock RTC ) it using following code
unsigned long epochTime = timeClient.getEpochTime();
and then I use
rtc.Write(epochTime);
and then I am using following code to read back values I just wrote ( after few statements )
Serial.print("read back ecpoch = ");
Serial.println(rtc.Read());
and read back value is way off , what I am doing wrong…?
I think its mentioned in the library author’s note,
This function doesn’t return time in the same format as the getFormattedTime() function, so you will have to pay attention to how its formatting, detailes of the code can be found here
thanks for code referral, but my question is after using rtc,Write(NTPclient.getEpochTime()) read back values should differ by few seconds , but in my case it is different by factors of thousands , for example using ntp time I am getting followings
date and time =22/12/2021 1:41:44
Seconds since Jan 1 1970 = 1640137304
and after writing to relal time clock I when I read back I am getting
read back ecpoch = 1608514904 ,why it is so much difference , I am not able to comprehend…?
OK, I used rtc_write (…) ( rtc c api library calls ) followed by rtc_read() now return epoch is correct, can someone determine is there a problem C++ RTC api…?