forked from ThingPulse/esp8266-weather-station
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNTPClient.h
44 lines (31 loc) · 1.02 KB
/
NTPClient.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
#pragma once
#include "Arduino.h"
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#define SEVENZYYEARS 2208988800UL
#define NTP_PACKET_SIZE 48
class NTPClient {
private:
WiFiUDP _udp;
const char* _poolServerName = "time.nist.gov"; // Default time server
int _port = 1337;
int _timeOffset;
unsigned int _updateInterval = 60000; // In ms
unsigned long _currentEpoc; // In s
unsigned long _lastUpdate = 0; // In ms
byte _packetBuffer[NTP_PACKET_SIZE];
void sendNTPPacket(IPAddress _timeServerIP);
public:
NTPClient(int timeOffset);
NTPClient(const char* poolServerName);
NTPClient(const char* poolServerName, int timeOffset);
NTPClient(const char* poolServerName, int timeOffset, int updateInterval);
void begin();
void update();
void forceUpdate();
String getHours();
String getMinutes();
String getSeconds();
String getFormattedTime();
unsigned long getRawTime();
};