NTPClient icon indicating copy to clipboard operation
NTPClient copied to clipboard

Give access to _lastUpdate would let users deal with better accuracy requirements

Open ybizeul opened this issue 8 years ago • 4 comments

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...

ybizeul avatar Jan 16 '17 13:01 ybizeul

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();

creeg2 avatar Jul 20 '17 01:07 creeg2

My pull request #22 includes this, feel free to grab my branch or apply that patch.

blackketter avatar Jul 20 '17 04:07 blackketter

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.

voanhcuoc avatar Dec 23 '19 00:12 voanhcuoc

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.

WhymustIhaveaname avatar Apr 25 '20 06:04 WhymustIhaveaname