-
Notifications
You must be signed in to change notification settings - Fork 422
/
Ntp.h
55 lines (43 loc) · 1.09 KB
/
Ntp.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
47
48
49
50
51
52
53
54
55
/*
* ntp.h
*
* Created on: 8 Mar 2016
* Author: joe
*/
#ifndef NTP_H_
#define NTP_H_
#include <ESP8266WiFi.h>
#include <ESPAsyncUDP.h>
#include <TimeLib.h>
#define NTP_PACKET_SIZE 48 // NTP time is in the first 48 bytes of message
struct deviceUptime
{
long days;
long hours;
long mins;
long secs;
};
class NtpClient
{
public:
void ICACHE_FLASH_ATTR Ntp(const char *server, int8_t tz, time_t syncSecs);
ICACHE_FLASH_ATTR virtual ~NtpClient();
static char *TimeServerName;
static IPAddress timeServer;
static int8_t timezone;
static time_t syncInterval;
static AsyncUDP udpListener;
static byte NTPpacket[NTP_PACKET_SIZE];
static ICACHE_FLASH_ATTR String iso8601DateTime();
static ICACHE_FLASH_ATTR deviceUptime getDeviceUptime();
static ICACHE_FLASH_ATTR String getDeviceUptimeString();
static ICACHE_FLASH_ATTR time_t getUtcTimeNow();
bool ICACHE_FLASH_ATTR processTime();
time_t getUptimeSec();
private:
static ICACHE_FLASH_ATTR String zeroPaddedIntVal(int val);
static ICACHE_FLASH_ATTR time_t getNtpTime();
protected:
time_t _uptimesec = 0;
};
#endif /* NTP_H_ */