-
Notifications
You must be signed in to change notification settings - Fork 383
Provide epoch in milliseconds #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
It wouldn't be possible without changing the data type returned by getEpochTime(). Right now the unix time is 1,575,693,824. Multiplying by 1000 will overflow the maximum value that an unsigned int can hold. Even if you did change the data type, the simple synchronization code used will never be accurate to the millisecond level - the answer would be more precise, but it would not much be more accurate. So, there's really no point. |
Need not change the datatype. Just add another float _current_epoc_dec to record the decimal part of the current time from the Epoch. I solved this in Pull Request #102. I add a new function named get_millis() which will return a float in [0,1000) recording the ms number of this second. |
@WhymustIhaveaname It would be useful to add a new method called getEpochTimeMs which returns a uint64_t containing the number of ms since 1-1-1970 because having 2 different calls (one getEpochTime and the other get_millis) could generate some drift if the second between the 2 calls changes (e.g. getepochtime returns 13/05/2020 08:41:59(.999) and get_millis returns 000 (meaning 13/05/2020 08:42:00.000) |
@fededim Thanks for your suggestion. I will add this function if my PR gets merged. But for now, you can add this function manually yourself.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I confirm the program from @WhymustIhaveaname works well. Here is a screenshot of 2 esp32s flashed using his NTPClient.h and NTPclient.cpp and a loop running at 10ms. Button were release at the the nearly same time (witch is tricky to clear the consoles and press tiny buttons). The main loop contain the following code: void loop() {
timeClient.update();
Serial.print(timeClient.getFormattedTime());Serial.print(".");
int ms = timeClient.get_millis();
if(ms<10){
Serial.print("00");Serial.println(ms);
}
else if(ms>=10 && ms<100){
Serial.print("0");Serial.println(ms);
}
else{
Serial.println(ms);
}
delay(10);
} |
Additional context
Additional requests
The text was updated successfully, but these errors were encountered: