Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

getUTCEpochMillis() not returning correct value #7

Closed
DavidSteinmann opened this issue Jan 24, 2022 · 2 comments
Closed

getUTCEpochMillis() not returning correct value #7

DavidSteinmann opened this issue Jan 24, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@DavidSteinmann
Copy link

The method getUTCEpochMillis() does not return the full 64 bits of the unsigned long long.
The compiler doesn't convert _currentEpoc to unsigned long long and discards all the bits after the 32-bit value when calculating.
I fixed this by explicitly casting _currentEpoc to unsigned long long.

Fix in NTPClient_Generic_Impl.h:

unsigned long long NTPClient::getUTCEpochMillis() 
{
  unsigned long long epoch;

  epoch  = (unsigned long long)this->_currentEpoc * 1000;                   // last time returned via server in millis
  epoch += (this->_currentFraction) / FRACTIONSPERMILLI;  // add the fraction from the server
  epoch += millis() - this->_lastUpdate;          // add the millis that have passed since the last update

  return epoch;
}

Additional Info:

IDE: Visual Studio 2022 with Visual Micro (with Arduino 1.6/1.8).
ESP32 Core Version:  1.0.6
Arduino IDE version: 1.8.19
OS: Windows 10 Home
@khoih-prog
Copy link
Owner

Hi @DavidSteinmann

Thanks for spotting and reporting the bug.

I'll update the master then publish a new release soon, certainly with your contribution noted.

I'm looking forward to receiving more contributions from you.

Best Regards,

khoih-prog added a commit that referenced this issue Jan 25, 2022
### Releases v3.7.1

1. Fix getUTCEpochMillis() bug. Check [getUTCEpochMillis() not returning correct value #7](#7)
2. Update Adafruit SAMD `Packages_Patches`
khoih-prog added a commit that referenced this issue Jan 25, 2022
### Releases v3.7.1

1. Fix getUTCEpochMillis() bug. Check [getUTCEpochMillis() not returning correct value #7](#7)
2. Update Adafruit SAMD `Packages_Patches`
khoih-prog added a commit that referenced this issue Jan 25, 2022
### Releases v3.7.1

1. Fix getUTCEpochMillis() bug. Check [getUTCEpochMillis() not returning correct value #7](#7)
2. Update Adafruit SAMD `Packages_Patches`
@khoih-prog
Copy link
Owner

Hi @DavidSteinmann

The new NTPClient_Generic releases v3.7.1 has just been published. Your contribution is noted in Contributions and Thanks

Best Regards,


Releases v3.7.1

  1. Fix getUTCEpochMillis() bug. Check getUTCEpochMillis() not returning correct value #7
  2. Update Adafruit SAMD Packages_Patches

@khoih-prog khoih-prog added the bug Something isn't working label Jan 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants