NTPClient
NTPClient copied to clipboard
Can we have a setEpochTime() method?
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
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?
Sure, but that is just adding an extra layer. NTPClient already has a private variable to store that timestamp, and functions that use it.
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;
}