NTPClient
NTPClient copied to clipboard
Give access to _lastUpdate would let users deal with better accuracy requirements
I'm working on an application that is time sensitive, at least in a relative way. I don't need exact microsecond precision of the returned time, but I need a more or less reliable way to determine at the millisecond where I'm standing compared to the epoch.
Simply giving access to _lastUpdate does the job I think, as I can now get a string representing a ms epoch that way :
unsigned long seconds = timeClient.getEpochTime();
unsigned long ms = (millis() - timeClient.getLastUpdate()) % 1000;
char ms_char[12];
sprintf(ms_char,"%lu%03lu",seconds,ms);
Now I don't know what the best design is for this library :
- Propose a
getMillisecondString()
- Simply let use deal with a public
getLastUpdate()
like I did - Deal with 64bit to return a
ms
epoch as a number...
I'd like to see a getEpochMillis() that just removes the "divide by 1000" from the current getEpochTime(). This would require support for the "unsigned long long" type.
unsigned long long getEpochMillis();
My pull request #22 includes this, feel free to grab my branch or apply that patch.
If one is interested in milliseconds, most of the time he only cares about the interval between 2 periods. In that case, my fork may help. It helps you obtain milliseconds from getEpochTime()
without a code change, but it's a compromise, so use it carefully.
I completed the decimal part of NTP, removed the communication latency, and added a new function get_millis() to get the ms of this second (which is a float). You can see my fork or Pull Request #102.