Skip to content

Commit 00c3355

Browse files
author
Germán Martín
committed
Set sync interval to short after connection error. Fix debug output
1 parent ea84e25 commit 00c3355

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

NtpClientLib.cpp

+21-5
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ time_t ntpClient::getTime() {
7676
client->_udp.stop();
7777
client->_lastSyncd = timeValue;
7878
#ifdef DEBUG
79-
Serial.printf("Succeccful NTP sync at %s", client->getTimeString(client->_lastSyncd));
79+
Serial.println("Succeccful NTP sync at ");
80+
Serial.println(client->getTimeString(client->_lastSyncd));
8081
#endif // DEBUG
8182
return timeValue;
8283
}
@@ -85,6 +86,7 @@ time_t ntpClient::getTime() {
8586
Serial.println("-- No NTP Response :-(");
8687
#endif //DEBUG
8788
client->_udp.stop();
89+
setSyncInterval(client->_shortInterval); // Retry connection more often
8890

8991
return 0; // return 0 if unable to get the time
9092
}
@@ -151,7 +153,8 @@ time_t ntpClient::getTime() {
151153
client->_udp.stop();
152154
client->_lastSyncd = timeValue;
153155
#ifdef DEBUG
154-
Serial.printf("Succeccful NTP sync at %s", client->getTimeString(client->_lastSyncd));
156+
Serial.println("Succeccful NTP sync at ");
157+
Serial.println(client->getTimeString(client->_lastSyncd));
155158
#endif // DEBUG
156159
return timeValue;
157160
}
@@ -160,7 +163,7 @@ time_t ntpClient::getTime() {
160163
Serial.println("-- No NTP Response :-(");
161164
#endif //DEBUG
162165
client->_udp.stop();
163-
166+
setSyncInterval(client->_shortInterval); // Retry connection more often
164167
return 0; // return 0 if unable to get the time
165168
}
166169
else {
@@ -322,13 +325,21 @@ time_t ntpClient::decodeNtpMessage(byte *messageBuffer) {
322325
timeTemp += SECS_PER_HOUR;
323326
#ifdef DEBUG
324327
Serial.println("Summer Time");
328+
#endif // DEBUG
325329
}
330+
#ifdef DEBUG
326331
else {
327332
Serial.println("Winter Time");
328-
#endif // DEBUG
329333
}
334+
#endif // DEBUG
330335
}
336+
#ifdef DEBUG
337+
338+
else {
339+
Serial.println("No daylight");
331340

341+
}
342+
#endif // DEBUG
332343
return timeTemp;
333344
}
334345

@@ -511,7 +522,12 @@ boolean ntpClient::setTimeZone(int timeZone)
511522

512523
void ntpClient::setDayLight(boolean daylight)
513524
{
514-
this->_daylight = daylight;
525+
_daylight = daylight;
526+
#ifdef DEBUG
527+
Serial.print("--Set daylight saving to ");
528+
Serial.println(daylight);
529+
530+
#endif // DEBUG
515531
}
516532

517533
//

0 commit comments

Comments
 (0)