Skip to content

NTPClient.getEpochTime() jumps an hour #52

@bradanlane

Description

@bradanlane

I am using the NTPClient on a Wemos D1 Mini (ESP8266). On occasion, my code is detecting that the return from NTPClient.update() then NTPClient.getEpochTime() has jumped an hour.
I have tested with different NTP server pools (time.nist.gov and pool.ntp.org). The occurrence of the jump is not consistent. I've recorded it in teh morning, event, and over night.

I'm looking for debugging suggestions.

I have the following code fragment (with some gorpy calculations removed):

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 0, 3600000); // interval is 1 hour
...
timeClient.begin();
...
... define and initialize some globals
...
void clock_loop() {
    current_ticks = millis();
    if (next_update < current_ticks) {
        if (timeClient.update()) {
            ... save values from previous iteration as last_epoc, last_hour, last_minute
            cur_epoch = timeClient.getEpochTime();
            ... fetch cur_hour and cur_minute and calc next_update
            Serial.printf("Clock updated: %02d, %02d (%lu  %lu)\n", cur_hour, cur_minute, cur_epoch);
        } else {
            // we will assume one minute has passed
            ... compute cur__hour and cur_minute and calc next_update (to be on a minute boundary)
            Serial.printf("Clock update failed: %02d:%02d\n", cur_hour, cur_minute);
        }
        if (ABS(COMBINE(_hours, _minutes) - COMBINE(last_hour, last_minute)) > 2) {
            // more than two minutes have elapsed. something went wrong
            Serial.printf("Clock jumped: from %02d:%02d to %02d:%02d\n", 
                        last_hour, last_minute, cur_hour, cur_minute);
        }
    }
}

Here is a snippet of my logging:

lock updated: 07:05  (1533798300 )
Clock updated: 07:06  (1533798360 )
Clock updated: 07:07  (1533798420 )
Clock updated: 07:08  (1533798480 )
Clock updated: 07:09  (1533798540 )
Clock updated: 07:10  (1533798600 )
Clock updated: 06:11  (1533795061 )
Clock jumped: from 07:10 to 06:11
Clock updated: 06:11  (1533795119 )
Clock updated: 06:12  (1533795120 )
Clock updated: 06:13  (1533795180 )
Clock updated: 06:14  (1533795240 )
Clock updated: 06:15  (1533795300 )

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions