ropg / ezTime

ezTime — pronounced "Easy Time" — is a very easy to use Arduino time and date library that provides NTP network time lookups, extensive timezone support, formatted time and date strings, user events, millisecond precision and more.
MIT License
327 stars 92 forks source link

NTP Polling Issue after Power Cycle #89

Open jesse59672 opened 4 years ago

jesse59672 commented 4 years ago

Hi guys - I am having issues with the NTP server polling:

I have an esp8266-12e which is continuously connected to wifi. After an occasional AC power loss the esp will immediately reconnect to the router, but internet is not available for some time until the cable modem connects to my ISP. So after this happens my time remains set to Epoch + millis() and does not appear poll/fetch time from the NTP server again (even after 30 minutes). I am using the default server and update interval.

My understanding from lib documentation is that the program should have recovered from this event and updated time after 30 minutes max. The only thing that I can think of that could possibly be causing this is the event code below for handling wifi loss/regain. Do you guys see anything wrong with it?

Aside from my issue above, do you guys have any tips for quickly reestablishing the time after network upsets? I know I could use a DNS library and continuously try to resolve google.com to detect internet and then updateNTP() but is there an easier way? Is setting updateInterval() very low the best solution?

  lostWiFiEvent = WiFi.onStationModeDisconnected([](const WiFiEventStationModeDisconnected & event) {
    networkUptime = 0;
  });
  gotWiFiEvent = WiFi.onStationModeGotIP([](const WiFiEventStationModeGotIP & event) {
    waitForSync(6);
    updateNTP();
    networkUptime = myLocalTime.now();
  });