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)