Regarding the update interval I found this inside the NtpClientLib.h file:
#define DEFAULT_NTP_INTERVAL 1800 // Default sync interval 30 minutes
#define DEFAULT_NTP_SHORTINTERVAL 15 // Sync interval when sync has not been achieved. 15 seconds
...
/**
* Changes sync period.
* @param[in] New interval in seconds.
* @param[out] True if everything went ok.
*/
bool setInterval (int interval);
/**
* Changes sync period in sync'd and not sync'd status.
* @param[in] New interval while time is not first adjusted yet, in seconds.
* @param[in] New interval for normal operation, in seconds.
* @param[out] True if everything went ok.
*/
bool setInterval (int shortInterval, int longInterval);
/**
* Gets sync period.
* @param[out] Interval for normal operation, in seconds.
*/
This does not make sense to me because the example uses NTP.setInterval(63), which implies that the server comm interval is 63 seconds (why?). Such a strange value where one would think that a value close to 86400 (24 hours) would be more appropriate.
But another thing is that I tried to get the time as string in a function that is executed once every 2 minutes:
SerialDebug.print ("Current time: ");
SerialDebug.println (NTP.getTimeDateString ());
Accordig to the header file when calling getTimeDateString() without parameter it will be executed with the parameter now() which is handled by library Time.cpp:
time_t now() {
// calculate number of seconds passed since last call to now()
while (millis() - prevMillis >= 1000) {
// millis() and prevMillis are both unsigned ints thus the subtraction will always be the absolute value of the difference
sysTime++;
prevMillis += 1000;
#ifdef TIME_DRIFT_INFO
sysUnsyncedTime++; // this can be compared to the synced time to measure long term drift
#endif
}
if (nextSyncTime <= sysTime) {
if (getTimePtr != 0) {
time_t t = getTimePtr();
if (t != 0) {
setTime(t);
} else {
nextSyncTime = sysTime + syncInterval;
Status = (Status == timeNotSet) ? timeNotSet : timeNeedsSync;
}
}
}
return (time_t)sysTime;
}
I don't understand a lot of what is happening here but I see no NTP call in any case...
What actually happens when I call the function with no parameter is that the NTP server gets called to supply the current time!!!
So I get an NTP call every time I need to use the current time in any way...
Is there a way to fix this? It seems unnecessary to call NTP server with only minutes intervals...
PS: I had to copy the library files into my project so I could change the date format into ISO instead of the strange default format used. So now I can do also other changes if needed/suggested. DS