AceTime
0.8
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
|
A subclass of SystemClock that sync with its mReferenceClock using a blocking mReferenceClock->getNow() call. More...
#include <SystemClockLoop.h>
Public Member Functions | |
SystemClockLoop (Clock *referenceClock, Clock *backupClock, uint16_t syncPeriodSeconds=3600, uint16_t initialSyncPeriodSeconds=5, uint16_t requestTimeoutMillis=1000, common::TimingStats *timingStats=nullptr) | |
Constructor. More... | |
void | loop () |
Call this from the global loop() method. More... | |
![]() | |
void | setup () |
Attempt to retrieve the time from the backupClock if it exists. More... | |
acetime_t | getNow () const override |
Return the number of seconds since the AceTime epoch (2000-01-01T00:00:00Z). More... | |
void | setNow (acetime_t epochSeconds) override |
Set the time to the indicated seconds. More... | |
void | forceSync () |
Force a sync with the mReferenceClock. More... | |
acetime_t | getLastSyncTime () const |
Return the time (seconds since Epoch) of the last valid sync() call. More... | |
bool | isInit () const |
Return true if initialized by setNow() or syncNow(). More... | |
![]() | |
virtual | ~Clock () |
Virtual destructor. More... | |
virtual void | sendRequest () const |
Send a time request asynchronously. More... | |
virtual bool | isResponseReady () const |
Return true if a response is ready. More... | |
virtual acetime_t | readResponse () const |
Returns number of seconds since AceTime epoch (2000-01-01). More... | |
Static Public Attributes | |
static const uint8_t | kStatusReady = 0 |
Ready to send request. More... | |
static const uint8_t | kStatusSent = 1 |
Request sent, waiting for response. More... | |
static const uint8_t | kStatusOk = 2 |
Request received and is valid. More... | |
static const uint8_t | kStatusWaitForRetry = 3 |
Request received but is invalid, so retry with exponential backoff. More... | |
![]() | |
static const acetime_t | kInvalidSeconds = LocalTime::kInvalidSeconds |
Friends | |
class | ::SystemClockLoopTest_loop |
Additional Inherited Members | |
![]() | |
SystemClock (const SystemClock &)=delete | |
SystemClock & | operator= (const SystemClock &)=delete |
SystemClock (Clock *referenceClock, Clock *backupClock) | |
Constructor. More... | |
virtual unsigned long | clockMillis () const |
Return the Arduino millis(). More... | |
void | keepAlive () |
Call this (or getNow() every 65.535 seconds or faster to keep the internal counter in sync with millis(). | |
void | backupNow (acetime_t nowSeconds) |
Write the nowSeconds to the backupClock (which can be an RTC that has non-volatile memory, or simply flash memory which emulates a backupClock. | |
void | syncNow (acetime_t epochSeconds) |
Similar to setNow() except that backupNow() is called only if the backupClock is different from the referenceClock. More... | |
![]() | |
Clock *const | mReferenceClock |
Clock *const | mBackupClock |
acetime_t | mEpochSeconds = kInvalidSeconds |
acetime_t | mLastSyncTime = kInvalidSeconds |
uint16_t | mPrevMillis = 0 |
bool | mIsInit = false |
A subclass of SystemClock that sync with its mReferenceClock using a blocking mReferenceClock->getNow() call.
The blocking call can be a problem for clocks like NtpClock which makes a network request. If this is a problem, use SystemClockCoroutine instead.
Initial syncing occurs at initialSyncPeriodSeconds interval, until the first successful sync, then subsequent syncing occurs at syncPeriodSeconds interval. Initial syncing implements an exponential backoff when the sync request fails, increasing from initialSyncPeriodSeconds to until a maximum of syncPeriodSeconds.
Definition at line 29 of file SystemClockLoop.h.
|
inlineexplicit |
Constructor.
referenceClock | The authoritative source of the time. If this is null, the object relies just on clockMillis() and the user to set the proper time using setNow(). |
backupClock | An RTC chip which continues to keep time even when power is lost. Can be null. |
syncPeriodSeconds | seconds between normal sync attempts (default 3600) |
initialSyncPeriodSeconds | seconds between sync attempts when the systemClock is not initialized (default 5), exponentially increasing (2X) at each attempt until syncPeriodSeconds is reached |
timingStats | internal statistics |
Definition at line 58 of file SystemClockLoop.h.
|
inline |
Call this from the global loop() method.
This uses a blocking call to the mReferenceClock.
Definition at line 75 of file SystemClockLoop.h.
|
static |
Request received and is valid.
Definition at line 38 of file SystemClockLoop.h.
|
static |
Ready to send request.
Definition at line 32 of file SystemClockLoop.h.
|
static |
Request sent, waiting for response.
Definition at line 35 of file SystemClockLoop.h.
|
static |
Request received but is invalid, so retry with exponential backoff.
Definition at line 41 of file SystemClockLoop.h.