Comments (2)
I have come across this too and was hoping for an event that might be fired off when the time is synced with NTP successfully.
I have a project that requires very accurate time but may be offline. It is using an RTC as it's time source but synced/Set with ezTime. If the device boots with no internet, it relies on the battery backed RTC only, then theoretically, once the device has internet it will update the RTC. I was using the RTC time to set ezTime on boot but confused that when I called a function containing waitForSync() to update the time on the RTC after internet was connected, it did not update.
i.e
DateTime now = rtc.now();
UTC.setTime(now.unixtime());
if (waitForSync(10)){ //Get the time from the internet..
rtc.adjust(DateTime(UTC.now())); //Set the time on the RTC
}
UTC.now() will actually be the rtc time and not the internet time, regardless of internet connectivity.
waitForSync() does not seem to actually check internet time if timeStatus() == timeSet (which seems to be the case if you have called setTime() less than 1hr ago.
Because my project will behave differently between RTC time and ezTime, i need to know when ezTime has synced with NTP rather than the RTC.
Author seems to be MIA this year...
Edit: This is confirmed by the source - Line 537 of ezTime.cpp...
if (_time_status != timeSet) {
infoln(F("Waiting for time sync"));
while (_time_status != timeSet) {
if ( timeout && (millis() - start) / 1000 > timeout ) { triggerError(TIMEOUT); return false;};
delay(250);
events();
}
infoln(F("Time is in sync"));
}
So because the time is set, regardless of the source, it's not actually checking internet time...
from eztime.
I managed to work around this issue by reviewing the source code of the library
If you call updateNTP()
directly, rather than using waitForSync()
(Which calls uptateNTP()
but only if time_status !=timeSet
) the time_status
should now be either timeNeedsSync
or timeSet
, purely based on NTP success/fail.
Unfortunately, updateNTP()
does not return a variable itself.
I ended up with:
void syncTimeToRTC(){
//Force the ezTime library to try internet time
updateNTP();
// time_status should now be either timeNeedsSync or timeSet
if (timeStatus() == timeSet){
rtc.adjust(DateTime(UTC.now())); //Set the time on the RTC
rtcInUse = 0;
}else{
// Relying on RTC time
DateTime now = rtc.now();
UTC.setTime(now.unixtime()); //Set EZTime to whatever the RTC is.
rtcInUse = 1;
lastFailure = millis();
}
}
By setting an if statement such as:
if (millis() - lastFailure > 60000 && rtcInUse == 1) syncTimeToRTC();
I can make sure it's always in sync.
I also run it if network gets disconnected/reconnected.
from eztime.
Related Issues (20)
- hour() is off when passing in a timestamp, or I'm using it wrong? HOT 2
- can't set time zone for Asia/Tehran
- Improving library features
- Asia/Jerusalem returns empty posix string HOT 1
- readme update for "different languages"
- examples Timezones.ino proposed enhancement - thanks
- Dublin timezone incorrect time HOT 1
- 'myTZ was not declared in this scope'
- Feature request
- day(t) seems to return incorrect value
- Using ezTime with nodemcu-32s w/64x32 HUb75 LED Matrix HOT 5
- Stack problem whtn activate the waitForSync
- ezTime for ESP32 Wired Ethernet on Olimex ESP32-POE-ISO Working
- Won't sync with NTP if module can't access internet HOT 1
- It doesn't work with Lan8720 ethernet.
- Library without interruptions suggestion HOT 2
- Use ip-api.com to fetch timezone offsets more accurately? HOT 3
- Timezone data is not correct for Europe/Dublin
- Global Scope Enumerations Prevent Compilation
- Timezone lookup for: <TZ> ... ERROR: Timeout
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eztime.