Skip to content

Can we have a setEpochTime() method? #26

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

Open
sheffieldnikki opened this issue Mar 21, 2017 · 3 comments
Open

Can we have a setEpochTime() method? #26

sheffieldnikki opened this issue Mar 21, 2017 · 3 comments
Labels
type: enhancement Proposed improvement

Comments

@sheffieldnikki
Copy link
Contributor

Could we have a way of manually setting the internal time stored by NTPClient please? e.g., a setEpochTime(t) to match the existing getEpochTime().

My use case is reading the NTP time over the network no more than once a day, between which the ESP8266 spends much of its time in deep sleep mode, so I'm storing the predicted wake time/date in RTC memory, and I'd like to write that into NTPClient when REASON_DEEP_SLEEP_AWAKE (but not for other reset methods like power on).

Thanks

@TyIsI
Copy link

TyIsI commented Apr 22, 2017

Why not wrap that into a function that reads your cached time and if you don't have a cached time, it reads from NTPClient?

@sheffieldnikki
Copy link
Contributor Author

Sure, but that is just adding an extra layer. NTPClient already has a private variable to store that timestamp, and functions that use it.

@sheffieldnikki
Copy link
Contributor Author

I've added the obvious code, in case anyone wants to use it.

NTPClient.h:

/**
 * Replace the NTP-fetched time with seconds since Jan. 1, 1970
 */
void setEpochTime(unsigned long secs);

NTPClient.cpp:

void NTPClient::setEpochTime(unsigned long secs) {
  this->_currentEpoc = secs;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

3 participants