-
Notifications
You must be signed in to change notification settings - Fork 1
/
wifi.ino
96 lines (61 loc) · 1.89 KB
/
wifi.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
#include "wifi.h"
void wifiStartAP() {
#ifdef serialDebug
Serial.println("start soft wifi");
#endif
WiFi.mode(WIFI_AP);
sprintf(localAPssid, "openhivescale_%d", ESP.getChipId());
WiFi.softAP(localAPssid);
IPAddress myIP = WiFi.softAPIP();
#ifdef serialDebug
Serial.println("AP IP address: ");
Serial.println(myIP);
#endif
debug("AP IP address: ");
debug(myIP);
}
void wifiStart() {
unsigned long wifiStart;
if (!wifiStarted) {
wifiStarted = 1;
wifiStart = millis();
debug("Connecting");
//Connexion au wifi
char ssid[50];
char pw[50];
String ssidStr = readSetting("wifiHotspotSSID");
ssidStr.toCharArray(ssid, 50);
String pwStr = readSetting("wifiHotspotPassword");
pwStr.toCharArray(pw, 50);
WiFi.begin(ssid,pw);
debug("Avant wifi start : " + String(WiFi.status()));
while ((WiFi.status() != WL_CONNECTED) && ((millis() - wifiStart) < 20000))
{
delay(100);
debug(String(WiFi.status()), true);
}
debug("");
if (WiFi.status() != WL_CONNECTED) {
debug("Wifi connection failed.... " + String(WiFi.status()));
//RTCClearInterrupt(); // => switch OFF
}
debug("Fin wifi start : " + String(WiFi.status()));
File logfile = SPIFFS.open("/wifilog.txt", "a");
logfile.println("");
logfile.println(nowStr());
logfile.println("Fin wifi start : " + String(WiFi.status()));
logfile.close();
unsigned long wifiConnected;
wifiConnected = millis();
debug(wifiConnected);
}
}
void wifiStop() {
if (wifiStarted == 1) {
// Insert whatever code here to turn off all your web-servers and clients and whatnot
WiFi.disconnect();
WiFi.forceSleepBegin();
delay(1);
//For some reason the modem won't go to sleep unless you do a delay(non-zero-number) -- no delay, no sleep and delay(0), no sleep
}
}