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

getUTCEpochMillis() not returning correct value #7

Closed
@DavidSteinmann

Description

@DavidSteinmann

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions