-
Notifications
You must be signed in to change notification settings - Fork 1
/
myWiFi.h
63 lines (53 loc) · 1.33 KB
/
myWiFi.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
// myWiFi.h
// the functions for connecting to wifi and get the ntp time
#pragma once
/* Start WiFi and Connect to Network */
boolean connectWiFi() {
WiFi.disconnect();
WiFi.mode(WIFI_STA);
WiFi.config(ip, gateway, subnet, dns);
WiFi.begin(ssid, password);
boolean state = true;
String hostname(HOSTNAME);
WiFi.setHostname(hostname.c_str());
int i = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (i > 60) {
state = false;
break;
}
i++;
}
// serial output of connection details
if (state) {
Serial.print(F("\nConnected to "));
Serial.println(ssid);
Serial.print(F("IP address: "));
Serial.println(WiFi.localIP());
}
else {
Serial.println("Connection failed.");
}
return state;
}
bool getTime() { // Zeitzone einstellen https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv
configTzTime("CET-1CEST,M3.5.0/02,M10.5.0/03", ntpServer[0]); // deinen NTP Server einstellen (von 0 - 5 aus obiger Liste)
if (!getLocalTime(&tm)) return false;
return true;
}
bool setupTime() {
if (!getTime()) {
Serial.println("Zeit konnte nicht geholt werden\n");
return false;
}
else {
Serial.print("Time synced\n");
return true;
}
}
bool checkWiFi() {
if (WiFi.status() != WL_CONNECTED) return false;
else return true;
}