Skip to content

Provide millisToEpoch and isSynced functions #136

Open
@hgrecco

Description

@hgrecco

There is a feature that I need in multiple projects and I wonder if there is any interest to have it upstream. Briefly, I use arduino (and similar devices) to acquire data at 1 Hz from sensors and then upload it to a server. It is not uncommon that that due to the location of the sensor WiFi is not available from the very beginning and therfore the data is stored in a buffer. As soon as WiFi is available I start transmiting the buffer data to the server. But I need to make sure that the NTPClient has been synced first (that is why I need isSynced function). Currently I am either checking if the date is too old and/or _lastUpdate is zero. Then I have to convert the value of millis that I have stored in each record (insteado of the epoch) and convert it to Epoch. For this purpose I just do:

unsigned long millisToEpoch(unsigned long value) const {
  return this->_timeOffset + // User offset
         this->_currentEpoc + // Epoc returned by the NTP server
         ((value - this->_lastUpdate) / 1000); // Time since last update
}

In both cases I need to copy NTPClient as there all these members are private. Have you considered adding these functions or at least making these members protected so we can add this behaviour via subclassing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions