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

setting time manually when there is no internet #27

Closed MosCD3 closed 5 years ago

MosCD3 commented 5 years ago

This library is really helpful and great.

I have a master controller in my project which connects to the internet so ezTime works fine with it however, in my project there are other controllers that doesn't have an internet access, yet depends on the clock for some operations. What I want to do is, let the controllers connect to the Hub and get some data to be used to set ezTime manually and offline to calculate the time. I can't seem to find a clear answer in the documentation.\

It would be also useful if there is a function in ezTime to return that last pinged Unix Time Stamp may be to pass it to other controllers to calulate time manually without having to sync with ntp server

ropg commented 5 years ago

If you call setInterval(0) (or simply setInterval()), the unit that is not connected to the internet will stop trying to reach the NTP server. If this is an AVR or something else with very little flash, you could compile on the non-connected units after commenting out #define EZTIME_NETWORK_ENABLE in src/ezTime.h to save quite a lot of space.

You can then call UTC.now() on the internet-connected station to get the current timestamp, send it to the non-connected one and use UTC.setTime(timestamp) there to set the time.