-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDST.ino
170 lines (151 loc) · 4.19 KB
/
DST.ino
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <NTPClient.h>
#include <WiFi.h>
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
String formattedDate;
String dayStamp;
String timeStamp1;
// define your SSID's, and remember to fill out variable ssidArrNo with the number of your SSID's
String ssidArr[] = {"Enterprise-pro", "Enterprise_EXT", "Enterprise_EXTN", "Enterprise" };
int ssidArrNo = 4;
const char* ssid = ""; // no need to fill in
const char* password = "gp44pnh6";
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 3600;
void setup() {
Serial.begin(115200);
Serial.println("Void Setup");
// Start WiFi and update time
connectToNetwork();
Serial.println(" ");
Serial.println("Connected to network");
timeClient.setTimeOffset(gmtOffset_sec);
while (!timeClient.update()) {
timeClient.forceUpdate();
}
// The formattedDate comes with the following format:
// 2018-05-28T16:00:13Z
// We need to extract date and time
formattedDate = timeClient.getFormattedDate();
// Extract date
int splitT = formattedDate.indexOf("T");
dayStamp = formattedDate.substring(0, splitT);
dayStamp = dayStamp.substring(5);
String dateMonth = dayStamp.substring(0, 2);
String dateDay = dayStamp.substring(3, 5);
dayStamp = dateDay + "-" + dateMonth;
timeStamp1 = formattedDate.substring(splitT + 1, formattedDate.length() - 1);
// config.time = timeStamp1.substring(0, 5);
// variables needed for DST test
int thisHour = timeClient.getHours();
int thisDay = dateDay.toInt();
int thisMonth = dateMonth.toInt();
int thisWeekday = timeClient.getDay();
bool dst = false;
// Test for DST active
if (thisMonth == 10 && thisDay < 25 && thisWeekday < 7 ) {
dst = true;
}
if (thisMonth == 10 && thisDay > 24 && thisWeekday == 7 && thisHour < 2) {
dst = true;
}
if (thisMonth < 10 && thisMonth > 3) {
dst = true;
}
if (thisMonth == 3) {
dst = true;
if (thisDay < 25) {
dst = false;
}
else
// thisDay > 25
{
if (thisWeekday == 7 && thisHour < 2) {
dst = false;
}
else {
if (thisWeekday == 7) {
dst = true;
}
else {
if (thisWeekday < 7) {
int checkSum = thisDay - thisWeekday + 7;
if (checkSum > 31) {
dst = true;
}
else {
dst = false;
}
}
}
}
}
}
if (dst) {
Serial.println("IN SOMMERTIME");
timeClient.setTimeOffset(gmtOffset_sec + 3600);
while (!timeClient.update()) {
timeClient.forceUpdate();
}
// The formattedDate comes with the following format:
// 2018-05-28T16:00:13Z
// We need to extract date and time
formattedDate = timeClient.getFormattedDate();
// Extract date
int splitT = formattedDate.indexOf("T");
dayStamp = formattedDate.substring(0, splitT);
dayStamp = dayStamp.substring(5);
String dateMonth = dayStamp.substring(0, 2);
String dateDay = dayStamp.substring(3, 5);
dayStamp = dateDay + "-" + dateMonth;
timeStamp1 = formattedDate.substring(splitT + 1, formattedDate.length() - 1);
} else {
Serial.println("IN VINTERTIME");
}
}
void connectToNetwork() {
Serial.print("Size of SSID array ");
Serial.println(ssidArrNo);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
bool breakLoop = false;
for (int i = 0; i <= ssidArrNo; i++) {
ssid = ssidArr[i].c_str();
Serial.print("SSID name: ");
Serial.print(ssidArr[i]);
while ( WiFi.status() != WL_CONNECTED )
{
// wifi down, reconnect here
WiFi.begin(ssid, password);
int WLcount = 0;
int UpCount = 0;
while (WiFi.status() != WL_CONNECTED )
{
delay( 100 );
Serial.printf(".");
if (UpCount >= 60) // just keep terminal from scrolling sideways
{
UpCount = 0;
Serial.printf("\n");
}
++UpCount;
++WLcount;
if (WLcount > 200) {
Serial.println("we should break");
breakLoop = true;
break;
}
}
if (breakLoop) {
breakLoop = false;
break;
}
}
}
if (WiFi.status() != WL_CONNECTED) {
return;
}
}
void loop() {
}