-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwifi.ino
More file actions
27 lines (25 loc) · 860 Bytes
/
wifi.ino
File metadata and controls
27 lines (25 loc) · 860 Bytes
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
void connectToWifi() {
if ( ! WiFi.isConnected() ) {
Serial.println();
Serial.println("Connecting to Wi-Fi...");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
}
}
void WiFiEvent(WiFiEvent_t event) {
Serial.println();
Serial.printf("[WiFi-event] event: %d\n", event);
switch (event) {
case SYSTEM_EVENT_STA_GOT_IP:
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
xTimerStop(wifiReconnectTimer, 0); // ensure we don't try to reconnect to Wi-Fi while reconnected
xTimerStart(mqttReconnectTimer, 0);
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
Serial.println("WiFi lost connection");
xTimerStop(mqttReconnectTimer, 0); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
xTimerStart(wifiReconnectTimer, 0);
break;
}
}