NTPClient icon indicating copy to clipboard operation
NTPClient copied to clipboard

Add offline time update to NTPClient capability

Open saifuhameed opened this issue 3 years ago • 1 comments

In my application NTPClient is used to get time for logging and displaying IOT events. We expect device to display IOT data through local webserver even without internet. But there is a problem, event time will be wrong due to there is no internet. So I suggest to add a function to enable offline updating of date and time, so that it will give at least actual date and time with reduced accuracy. Offline updating can be done from a settings page of IOT application, user can update date and time on device startup. This feature can be easily accommodated by adding a function to update _lastUpdate and _currentEpoc manually.

saifuhameed avatar Oct 06 '21 12:10 saifuhameed

You can update the current time manually through the offset:

  // Setup
  WiFiUDP ntpUDP;
  NTPClient timeClient(ntpUDP);
  // Update
  timeClient.setTimeOffset(currentEpoch - millis() / 1000);

The last part tries to compensate _lastUpdate. It is the best solution I've found so far and it is not accurate. There should be an easier way to do this. Hopefully this library will get this feature.

Walorikot avatar Mar 25 '24 20:03 Walorikot