Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If syncProvder is set but does not return time, subsequent calls to now() should try to sync. #15

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

karl-petter
Copy link
Contributor

I use a GSM modem to sync my time. When I initialise my program I call setSyncProvider to set my getTImeFunction. Though at that time the modem is not turned on neither has it connected to the mobile network and thus the sync attempt in now() will fail. But subsequent calls after I have taken the modem online will return a none synced time even if the sync service is available. Once syncInterval has passed now() will make a new sync attempt.

Instead I would like now() to try to sync everytime as long as the status is timeNotSet. The provided code takes care of this.

Also changed the indentation to spaces instead of tabs of my previous commit.

@michaelmargolis
Copy link
Collaborator

I do not want to interfere with the existing capability for the caller to recognize that the sync function has not set the time so an alternative sync source can be used if available. What are the disadvantages of adding the functionality you require in the sketch instead of in the library?

@karl-petter
Copy link
Contributor Author

The main issue is that Time does not provide any forced way to sync. At least not obviously from the API point of view. But of course a new call to setSyncProvider() or change the setSyncInterval to 0 would achieve that. Though I think it would be a bit strange to first setup Time and then change sync interval until I have seen it has synced. What I want to achieve is that I as soon as possible get a correct time and not something like 1970-ish.

And my change does not remove the existing capability for the caller to recognise that sync has not set time. Status is still timeNotSet after now() was called and the caller can check status and decide to either call now() again to try to sync again(which existing code will not allow) or set an alternative sync source. But of course the alternative to achieve this same functionality is to call setSyncInterval(0) and then call now() and once status has changed to timeSet, call setSyncInterval(300).

I guess it depends on how one looks at syncInterval, is that the exact interval at which the getTimeFunction will be called or is it the amount a time that will pass at least until getTimeFunction is called.

@wayfarerbasta
Copy link

@karl-petter

Hi I have a similar problem. I'm not sure why, but sometimes the internal sync functionality of the library does not work at all.
I implementet an external synchronisation based on the setTime function of the library and I use a global variable to set the sync status in my sycProvider function.

wayfarer

@michaelmargolis
Copy link
Collaborator

wayfarerbasta, is the problem that the time source is not available when the system starts (which I believe is the issue raised by karl-petter. Or is the sync functionality intermittently not working? If the latter, can you say more about how to reproduce this problem.

@hberg32
Copy link

hberg32 commented Oct 15, 2016

I find that I sometimes get timeouts on the first sync attempt after powering up an ESP8266 and connecting to Wifi. I'd like to suggest simply adding the following to Time.cpp (and TimeLib.h). The sketch can determine for itself if the time is not set and kick off another one if needed.

void syncNow()
{
nextSyncTime = 0;
now();
}

@scr34m88
Copy link

I know this thread is a long time ago, but I think this is what I need..

I've got a clock with a RTC and i want to sync it every hour.
When I use
setSyncProvider(RTC.get); // Zeit vom RTC bekommen setSyncInterval(60000);
sometimes it dosent work an the wrong time is displayed and i have to reset the arduino.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants