Skip to content

Commit ecd97c8

Browse files
committed
Return last actual offset
1 parent 81ad49c commit ecd97c8

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

examples/ledFlasher/ledFlasher.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ void processSyncEvent (NTPEvent_t ntpEvent) {
3232
ntpEvent.info.port,
3333
ntpEvent.info.offset * 1000,
3434
ntpEvent.info.delay * 1000);
35-
}
35+
} /*else if (ntpEvent.event == partlySync) {
36+
Serial.printf ("[NTP-event] Partial sync %s Offset %0.3f\n",
37+
NTP.getTimeDateStringUs (),
38+
ntpEvent.info.offset * 1000);
39+
}*/
3640
}
3741

3842

src/ESPNtpClient.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void NTPClient::processPacket (struct pbuf* packet) {
159159
NTPPacket_t ntpPacket;
160160
bool offsetApplied = false;
161161
static bool wasPartial;
162+
static double lastOffset;
162163

163164
if (!packet) {
164165
DEBUGLOG ("Received packet empty");
@@ -214,6 +215,7 @@ void NTPClient::processPacket (struct pbuf* packet) {
214215
DEBUGLOG ("Next sync programmed for %d ms", FAST_NTP_SYNCNTERVAL);
215216
status = partialSync;
216217
wasPartial = true;
218+
lastOffset = offset;
217219
} else {
218220
DEBUGLOG ("Status set to SYNCD");
219221
DEBUGLOG ("Next sync programmed for %d seconds", getLongInterval ());
@@ -222,7 +224,7 @@ void NTPClient::processPacket (struct pbuf* packet) {
222224
offsetApplied = true;
223225
}
224226
//Serial.printf ("Status: %d wasPartial: %d offsetApplied %d Offset %0.3f\n", status, wasPartial, offsetApplied, ((float)tvOffset.tv_sec + (float)tvOffset.tv_usec / 1000000.0) * 1000);
225-
wasPartial = false;
227+
//wasPartial = false;
226228
}
227229
if (status == partialSync) {
228230
actualInterval = FAST_NTP_SYNCNTERVAL;
@@ -239,10 +241,16 @@ void NTPClient::processPacket (struct pbuf* packet) {
239241
NTPEvent_t event;
240242
if (status == partialSync){
241243
event.event = partlySync;
244+
event.info.offset = offset;
242245
} else {
243246
event.event = timeSyncd;
247+
if (wasPartial) {
248+
event.info.offset = lastOffset;
249+
} else {
250+
event.info.offset = offset;
251+
}
252+
wasPartial = false;
244253
}
245-
event.info.offset = offset;
246254
event.info.delay = delay;
247255
event.info.serverAddress = ntpServerIPAddress;
248256
event.info.port = DEFAULT_NTP_PORT;

0 commit comments

Comments
 (0)