arduino-libraries / NTPClient

Connect to a NTP server
554 stars 376 forks source link

Add handling for NTP server returning 0 #193

Closed frankB415 closed 5 months ago

frankB415 commented 1 year ago

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;
dallday commented 1 year ago

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?

gbanka commented 1 year ago

I got the same error while offline for ~14 hours. I was using getEpochTime()

Leonti commented 12 months ago

Also had the issue with my watering system which has the following logic:

  1. Compare the scheduled time with the current time
  2. 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 106829 which is in 12.20 years, which is also year 2036.
per1234 commented 5 months ago

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.