Skip to content

Commit a2f3127

Browse files
committed
Fixed NTPClient, inspired by arduino-libraries/NTPClient#211
1 parent b515f68 commit a2f3127

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

firmware/lib/NTPClient/NTPClient.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ bool NTPClient::forceUpdate() {
102102
timeout++;
103103
} while (cb == 0);
104104

105-
this->_lastUpdate = millis() - (10 * (timeout + 1)); // Account for delay in reading the time
106-
107105
this->_udp->read(this->_packetBuffer, NTP_PACKET_SIZE);
108106

109107
unsigned long highWord = word(this->_packetBuffer[40], this->_packetBuffer[41]);
@@ -112,6 +110,15 @@ bool NTPClient::forceUpdate() {
112110
// this is NTP time (seconds since Jan 1 1900):
113111
unsigned long secsSince1900 = highWord << 16 | lowWord;
114112

113+
// Fixed upstream bug
114+
// See https://github.com/arduino-libraries/NTPClient/pull/211
115+
// che - 20250304
116+
if (secsSince1900 == 0) {
117+
// Invalid response from NTP server -> ignore
118+
return false;
119+
}
120+
121+
this->_lastUpdate = millis() - (10 * (timeout + 1)); // Account for delay in reading the time
115122
this->_currentEpoc = secsSince1900 - SEVENZYYEARS;
116123

117124
return true; // return true after successful update

0 commit comments

Comments
 (0)