Go Down

Topic: Problem with setSyncProvider() [from Time Library] (Read 2 times) previous topic - next topic

johncc


...
Below the code I printed the serial output. In this example two times the setting of the clock did not work, the third try runs and the clock output begins.
Code: [Select]

unsigned long getNtpTime()
{
  sendNTPpacket(timeServer); // send an NTP packet to a time server
    delay(500);
   
    if ( Udp.parsePacket() ) {
     ... guts ...
     return epoch;
     }
  return 0; // return 0 if unable to get the time
}



In order to succeed, getNtpTime must get an answer back with 0.5 sec-- I wonder if this is enough to be reliable?  The examples that came with the Time library I am using uses delay(1000) here, and is different in other ways.  Which Time library are you using?  I believe I am using http://playground.arduino.cc/Code/Time.

My time library does appear to attempt a sync at the time setSyncProvider is called, so as far as I can tell your code should work.

John

PaulS

Quote
My time library does appear to attempt a sync at the time setSyncProvider is called, so as far as I can tell your code should work.

But not JUST when setSyncProvider is called.

johncc


Quote
My time library does appear to attempt a sync at the time setSyncProvider is called, so as far as I can tell your code should work.

But not JUST when setSyncProvider is called.


Yes, expectation is probably that it be called every 5 sec per
Code: [Select]
setSyncInterval(5); // Set seconds between re-sync (5s for test only)


So what is the "flawed fundamental assumption" that you think he is making?  Maybe I am making it too.

purehunter

@johncc
the 500ms should be no problem. As I wrote: I always get the time, if I call getNtpTime(); with the method "setTime((time_t)getNtpTime());" the clock will always be set.
I'm using the same time lib, the files already came with IDE 1.0.1 and are from Jul and Sept 2011.

@PaulS
If just calling setSyncProvider(getNtpTime); is fundamentally wrong, I'm asking why is this method presented in every example?
I began with copy and paste.
And again: getNtpTime(); works well!! Just setSyncProvider(getNtpTime); does not return. And this must work independently from the chosen interval.

What I'm wondering now is that the function getNtpTime() is returning an "unsigned long" while setTime() -and maybe setSyncProvider internally also- is requesting "time_t". I know, there is only a pointer argument in the call setSyncProvider(getNtpTime); , but somehow the time has to be transferred.


PaulS

Quote
So what is the "flawed fundamental assumption" that you think he is making?  Maybe I am making it too.

That setSyncProvider() needs to be called every time a sync is to occur, and that that is the only time the sync occurs.

Go Up