-
Notifications
You must be signed in to change notification settings - Fork 1
/
myNTP.h
92 lines (66 loc) · 1.92 KB
/
myNTP.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef __myNTP__
#define __myNTP__
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <time.h>
#include <WiFiUDP.h>
class myNTP{
private:
unsigned int localPort = 2390; // local port to listen for UDP packets
IPAddress timeServerIP; // time.nist.gov NTP server address
const char* ntpServerName = "0.europe.pool.ntp.org";
/*
time.nist.gov
pool.ntp.org
0.europe.pool.ntp.org
1.europe.pool.ntp.org
2.europe.pool.ntp.org
3.europe.pool.ntp.org
*/
const int PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[ 48 ]; //buffer to hold incoming and outgoing packets
byte ntp_timeDIFF=1;//unixtime+1h = Berlin
unsigned long ntp_getMillis;
unsigned long ntp_zeitchecker = 15000;//ms = 15sec
unsigned long ntp_zeitcheckeriftime = 5*60*1000;//5min, wenn zeit mal geholt
unsigned long requestWait=0;
unsigned long ntp_zeitcheckerWaitNTP=1000;//ms = 1sec
unsigned long uhr_previousMillis=0;
unsigned long uhr_zeitchecker =1000;//ms = 1sec intervall, Uhr aktualisieren
byte versuche=0;
byte versuchemax=5;
bool ntpangefragt=false;
bool hatntptime=false;
bool issummertimechecked=false;
unsigned long ntp_timestamp;//Zeit von NTP-Zeit ankam
unsigned long ntp_unixtime; //Zeit aus dem netz
int ntp_year=0;
byte ntp_month=0;
byte ntp_day=0;
byte ntp_wochentag=0;
byte ntp_stunde=0;
byte ntp_minute=0;
byte ntp_secunde=0;
WiFiUDP udp;
void getNTPTime();
void sendNTPpacket(IPAddress& address);
void checkNTPTime();
bool summertime(int year, byte month, byte day, byte hour, byte tzHours);
public:
void begin();
void update();
void setTimeDiff(byte t);
bool hatTime();
bool istTimeWHM(byte wochentag,byte hh, byte min);
bool isSummertime();
int getyear();
byte getmonth();
byte getday();
byte getwochentag();
byte getstunde();
byte getminute();
byte getsecunde();
byte getUTCtimediff();
};
#endif