EasyNTPClient icon indicating copy to clipboard operation
EasyNTPClient copied to clipboard

How do I know if getServerTime() succeeded?

Open brianjmurrell opened this issue 7 years ago • 2 comments

It's entirely possible that getServerTime() could fail in which case I'd want to keep calling it until it succeeds or some timeout is reached.

But there is no way for me to know if it was successful since it's private and I only get access to it indirectly through getUnixTime() which is skewed by millis().

So ultimately, I have no way of knowing if I can rely on what getUnixTime() is telling me other than to use some "less than some smallish-value" type heuristics.

I think the library either needs a flag to indicate that the time is accurate (i.e. there was a successful NTP transaction) or getUnixTime() should return 0 until the time is accurate the way getServerTime() does.

brianjmurrell avatar Jan 29 '18 15:01 brianjmurrell

Hi .. good question..i want to use this lib...but sure need to know if time is acurate. this dateTime will be the timeStamp for the data in the cloud - would be great to get some feedback or info on this thx in advance

iCounterBOX avatar Jun 04 '18 06:06 iCounterBOX

As far as I can see the code right now (and I've tested it in my project), getUnixTime() returns <= 0 when there was an issue with getting the time from the server. This should be enough for a check if we got the real time

sgenov avatar Jan 30 '20 09:01 sgenov