This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pro2 PLUS] Random date changes
Hi Werk,

I'm still on the last build and not the new update debug output of epoch time is still running:

Timestamp: 1573932519
Timestamp: 1573932579
Timestamp: 1573932639
Timestamp: 1573932699
RTC current date: Oct 30 2018
RTC current time: 19:31:40
Sending NTP request to sync clock...
NTP replied
UTC time from NTP server: 18:31:41
RTC adjusted to local time: 19:31:41
RTC current date: Oct 30 2018
RTC current time: 19:31:40

Timestamp: 1540927960
Timestamp: 1540928020
Timestamp: 1540928080
Timestamp: 1540928140
Timestamp: 1540928200
Timestamp: 1540928260
Timestamp: 1540928320
Timestamp: 1540928380
Timestamp: 1540928440
Timestamp: 1540928500
Timestamp: 1540928560
Timestamp: 1540928620
Timestamp: 1540928680
Timestamp: 1540928740
Timestamp: 1540928800
Timestamp: 1540928860
Timestamp: 1540928920
Timestamp: 1573933779
Timestamp: 1573933839
Timestamp: 1573933899
Timestamp: 1573933959
Timestamp: 1573934019

So what did I lern until now… Epoch time gets corrected after the new NTP sync at minute 31 of an hour at this moment the RTC still has the right time and date.
Then the time again changes in the minute after Tuesday, 30-Oct-18 19:48:40 UTC in RFC 2822
Exactly one minute later after the last change. So I'm curious what happens in the next hour.

More and more I think the problem resides on the SyncProvider function, which runs every 3600s (1 hour) which seems when your system time gets wrong.
I don't know why this issue isn't happening to me, anyway later when I will get home I will try again.

In the meanwhile, after your tests, try find this line of code:


and disable it. If the problem disappear, we will start to know where the culprit is.
MeteoCercal - Air Quality Data
Click here to watch at my ThingSpeak channel

Next round - correct time lost at Tuesday, 30-Oct-18 20:47:40 UTC in RFC 2822

Resynced correctly at minute 31 of this hour.

Just disabled the sycProvider line.

I will give feedback in a few minutes.

Disabling the SyncProvider fixes the issue for me.

Found the problem:

 Serial.print("Timestamp: ");
 Serial.print("Timestamp RTC: ");

Gives back the following:

Timestamp: 1540939999

Timestamp RTC: 1573944799

So is not working properly.
What a mystery...

That is what I'm testing right now, and it is working for me, this may explain why I can't reproduce the problem. However, why is it working for me?

RTC Time: 1540937345
RTC Time2: 1540937379
Local Time: 1540937379
RTC Time: 1540937423
RTC Time2: 1540937439
Local Time: 1540937439
RTC Time: 1540937483
RTC Time2: 1540937499
Local Time: 1540937499
RTC Time: 1540937544
RTC Time2: 1540937559
Local Time: 1540937559
RTC Time: 1540937603

RTC_Time is the timestamp returned by the SyncProvider function. I'm testing it with a 45 seconds interval so its value can't be equal to RTC_Time2. Done just for checking what is retuned by the function.

RTC_Time2 is the timestamp read from the RTC right after the NTP update.
Local Time is obviously the local timestamp after NTP update (testing at 1 minute intervals).

time_t RTC_time2 =;          
Serial.print("RTC Time2: "); Serial.println(RTC_time2);          
Serial.print("Local Time: "); Serial.println(local);

Out of curiosity, what IDE version are you using? I'm compiling with 1.8.4, but I can also try with 1.8.6
MeteoCercal - Air Quality Data
Click here to watch at my ThingSpeak channel

Hi Werk,

things are getting even more strange:

 Serial.print("Timestamp: ");
 Serial.print("Timestamp RTC Unix: ");


WiFi connection is ON
Timestamp: 1540941636
Timestamp RTC Unix: 1573946436

So .unixtime() is doing strange things for me...
This comes from the time library, right?

I'm compiling with IDE 1.8.5 at the moment.
Yeah... seems that unixtime may not be performing always the same way.

If I'm not wrong comes from the RTCLib, not the Time library
MeteoCercal - Air Quality Data
Click here to watch at my ThingSpeak channel

Found it in RTClib.cpp

uint32_t DateTime::unixtime(void) const {
 uint32_t t;
 uint16_t days = date2days(yOff, m, d);
 t = time2long(days, hh, mm, ss);
 t += SECONDS_FROM_1970_TO_2000;  // seconds from 1970 to 2000

 return t;

with #define SECONDS_FROM_1970_TO_2000 946684800 in RTClib.h


static long time2long(uint16_t days, uint8_t h, uint8_t m, uint8_t s) {
return ((days * 24L + h) * 60 + m) * 60 + s;
Yes, maybe the problem resides in the conversion form NTP time to unixtime

Unix uses an epoch located at 1/1/1970-00:00h (UTC) and NTP uses 1/1/1900-00:00h. This leads to an offset equivalent to 70 years in seconds
MeteoCercal - Air Quality Data
Click here to watch at my ThingSpeak channel

My IDE is the latest 1.8.7 if that helps any Smile powered by WeatherDuino and Weewx

Users browsing this thread: 1 Guest(s)