NTPClient
NTPClient copied to clipboard
Add handling for NTP server returning 0
I had some issues with wrong date as i used that lib on an ESP32. After debugging i found, that the NTP server sends from time to time "0" as response.
So I added 3 lines to handle that issue.
NTPClient.cpp:113:
unsigned long secsSince1900 = highWord << 16 | lowWord;
if (secsSince1900 == 0 ) { // failure value!!
return false;
}
this->_currentEpoc = secsSince1900 - SEVENZYYEARS;
Just noticed the same problem where the date shows as 07/02/2036 07:28:16, which seems to be the 0 value + 70 years :) Is the problem with the UDP packet being returned and does it need a check to see if the correct packet has been received?
I got the same error while offline for ~14 hours. I was using getEpochTime()
Also had the issue with my watering system which has the following logic:
- Compare the scheduled time with the current time
- If it's time to water do the watering and update next watering time.
Suddenly yesterday all of my plants started watering and the next scheduled time was in
106829which is in 12.20 years, which is also year2036.
Hi @frankB415. Thanks for taking the time to submit an issue.
I see we have another report about this at https://github.com/arduino-libraries/NTPClient/issues/84.
It is best to have only a single issue per subject so we can consolidate all relevant discussion to one place, so I'll go ahead and close this in favor of the other.
If you end up with additional information to share, feel free to comment in the other thread.