Time library - first sync after initial setup is later then set in setSyncInterv

Hi folks,

I am using the time library, and I am trying to set it up to use an NTP server as the time source (using a modified version of the example provided).

I am initializing the library like this:

void setup()
{ 
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  Udp.begin(localPort);
  setSyncProvider(getNTPTime);
  Serial.println("Looking for a time");
  while(timeStatus()== timeNotSet);
  Serial.println("Got a Time");
  setSyncInterval(60);
}

getNTPTime is a function that queries the NTP server for a time. The first line of the function is a Serial.println(“In getNTPTime”);
The main loop outputs the current time every 10 seconds.

So, this is what I am expecting to see in the serial monitor:

Looking for a time
Got a Time
*current time every 10 seconds*
In getNTPTime every 60 seconds

Instead, when the program starts, it enters the getNTPTime once, synchronizes the clock, and the next sync happens only after 4-5 minutes. But after that it is working correctly, syncing every 60 seconds.
Why is this happening?

I have attached the full code, and here is a sample output:

Starting

In getNTPTime
Got Time Packet
Looking for a time
Got a Time
15:37
15:37
15:37
15:38
15:38
15:38
15:38
15:38
15:38
15:39
15:39
15:39
15:39
15:39
15:39
15:40
15:40
15:40
15:40
15:40
15:40
15:41
15:41
15:41
15:41
15:41
15:41
15:42
15:42
15:42
In getNTPTime
Got Time Packet
15:42
15:42
15:42
15:43
15:43
15:43
In getNTPTime
Got Time Packet
15:43
15:43
15:44
15:44
15:44
15:44
In getNTPTime
Got Time Packet
15:44
15:44
15:45
15:45

sketch_jul28e.ino (2.84 KB)

Which exact version of "the Time library" are you using?

The latest seems to be Time.zip from http://www.pjrc.com/teensy/td_libs_Time.html

Timestamp: March 30, 2013 16:07

The default sync interval is 5 minutes. That may be part of the problem. Maybe the version of the library you have doesn't update nextSyncTime when you set the interval.

johnwasser: Which exact version of "the Time library" are you using?

The latest seems to be Time.zip from http://www.pjrc.com/teensy/td_libs_Time.html

Timestamp: March 30, 2013 16:07

The default sync interval is 5 minutes. That may be part of the problem. Maybe the version of the library you have doesn't update nextSyncTime when you set the interval.

Thanks a lot, updating the library did solve my problem! :)

Thanks again!