NTPClient has now a method boolean isTimeValid()
which indicates whether the last update was successful or not. Clock will blink if it wasn't successful.
This commit is contained in:
parent
0d3896ca0d
commit
adb03d486b
@ -26,6 +26,8 @@ class NTPClient {
|
||||
|
||||
void sendNTPPacket();
|
||||
|
||||
boolean _timeValid = false;
|
||||
|
||||
public:
|
||||
NTPClient(UDP& udp);
|
||||
NTPClient(UDP& udp, long timeOffset);
|
||||
@ -69,6 +71,7 @@ class NTPClient {
|
||||
int getHours() const;
|
||||
int getMinutes() const;
|
||||
int getSeconds() const;
|
||||
boolean getTimeValid() const;
|
||||
|
||||
/**
|
||||
* Changes the time offset. Useful for changing timezones dynamically
|
||||
|
@ -66,6 +66,9 @@ bool NTPClient::forceUpdate() {
|
||||
Serial.println("Update from NTP Server");
|
||||
#endif
|
||||
|
||||
while(this->_udp->parsePacket() != 0)
|
||||
this->_udp->flush();
|
||||
|
||||
this->sendNTPPacket();
|
||||
|
||||
// Wait till data is there or timeout...
|
||||
@ -74,10 +77,13 @@ bool NTPClient::forceUpdate() {
|
||||
do {
|
||||
delay ( 10 );
|
||||
cb = this->_udp->parsePacket();
|
||||
if (timeout > 100) return false; // timeout after 1000 ms
|
||||
if (timeout > 100) {
|
||||
this->_timeValid = false;
|
||||
return false; // timeout after 1000 ms
|
||||
}
|
||||
timeout++;
|
||||
} while (cb == 0);
|
||||
|
||||
this->_timeValid = true;
|
||||
this->_lastUpdate = millis() - (10 * (timeout + 1)); // Account for delay in reading the time
|
||||
|
||||
this->_udp->read(this->_packetBuffer, NTP_PACKET_SIZE);
|
||||
|
@ -24,6 +24,10 @@ void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color) {
|
||||
}
|
||||
fg_color = bg_color;
|
||||
}
|
||||
if (ntpClient.getTimeValid()==false && ntpClient.getSeconds() & 1==0) {
|
||||
clear(window, bg_color);
|
||||
return;
|
||||
}
|
||||
int h = ntpClient.getHours();
|
||||
drawDigit(window, numbers3x5, 3, 5, 0, 1, h / 10, fg_color, invert);
|
||||
drawDigit(window, numbers3x5, 3, 5, 4, 1, h % 10, fg_color, invert);
|
||||
|
Loading…
Reference in New Issue
Block a user