use events for Wifi
This commit is contained in:
parent
c6ba1a0f07
commit
dd25bce34a
20
src/wifi.h
20
src/wifi.h
@ -2,19 +2,24 @@
|
||||
#include <ESP8266WiFiMulti.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
|
||||
class Wifi {
|
||||
namespace Wifi {
|
||||
|
||||
WiFiEventHandler stationConnectedHandler;
|
||||
|
||||
private:
|
||||
String currentSSID;
|
||||
String currentPsk;
|
||||
|
||||
public:
|
||||
void setup() {
|
||||
stationConnectedHandler = WiFi.onStationModeConnected([](const WiFiEventStationModeConnected& e) {
|
||||
Serial.println("Reconnected to network.");
|
||||
wifiConnected.signal();
|
||||
});
|
||||
|
||||
WiFi.hostname("esp-clock");
|
||||
|
||||
ESP8266WiFiMulti wifiMulti;
|
||||
wifiMulti.addAP("OpenWrt", "pnW#0trsWrt");
|
||||
// wifiMulti.addAP("IoT", "inT#0trsNgs");
|
||||
wifiMulti.addAP("Miracle", "adriana1978");
|
||||
WiFi.hostname("esp-clock");
|
||||
|
||||
Serial.println("Connecting to WiFi netowrk.");
|
||||
while (wifiMulti.run() != WL_CONNECTED) {
|
||||
@ -30,9 +35,6 @@ public:
|
||||
WiFi.forceSleepWake();
|
||||
WiFi.begin(currentSSID.c_str(), currentPsk.c_str());
|
||||
Serial.println("Reconnecting to WiFi netowrk...");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,4 +60,4 @@ public:
|
||||
Serial.print(rssi);
|
||||
Serial.println(" dBm");
|
||||
}
|
||||
} wifi;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user