-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimeClient.h
46 lines (35 loc) · 1.13 KB
/
TimeClient.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
#include <Arduino.h>
#include "DateTime.h"
// Represents a automatically synchronized NTP client.
// The only instance of TimeClientClass is a global variable `TimeClient`.
class TimeClientClass {
public:
// Creates a new instance of the TimeClientClass class.
// Do not call this constructor directly. Always use the global variable `TimeClient`.
TimeClientClass(unsigned long timeOffset);
// Gets the Unix timestamp of now.
unsigned long ticks();
// Gets a boolean value indicates whether the time client is synchronized.
bool isReady();
// Get a DateTime object in local time zone.
DateTime now();
// Initializes the time client.
void begin();
// Updates in the loop.
void update();
// Forces to update online.
void forceUpdate();
private:
void _internalUpdate();
unsigned long UPDATE_TIMEOUT = 2000;
unsigned long UPDATE_INTERVAL = 100 * 60 * 1000;
bool _hasBegun = false;
bool _isReady = false;
bool _isUpdating = false;
unsigned long _timeOffset;
uint8_t _updateRetries = 0;
unsigned long _updateStart = 0;
unsigned long _lastUpdate = 0;
};
extern TimeClientClass TimeClient;