Swap to AP mode if WiFi psk is wrong

This commit is contained in:
Gunnar Skjold
2023-06-11 09:45:17 +02:00
parent 5b6b9879b1
commit ca1c237776

View File

@@ -162,9 +162,9 @@ void debugPrint(byte *buffer, int start, int length);
#if defined(ESP32)
uint8_t dnsState = 0;
ip_addr_t dns0;
void WiFiEvent(WiFiEvent_t event) {
void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
switch(event) {
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
case ARDUINO_EVENT_WIFI_STA_GOT_IP: {
const ip_addr_t* dns = dns_getserver(0);
memcpy(&dns0, dns, sizeof(dns0));
@@ -178,6 +178,23 @@ void WiFiEvent(WiFiEvent_t event) {
dnsState = 1;
}
break;
}
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
wifi_err_reason_t reason = (wifi_err_reason_t) info.wifi_sta_disconnected.reason;
debugI_P(PSTR("WiFi disconnected, reason %s"), WiFi.disconnectReasonName(reason));
switch(reason) {
case WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT:
case WIFI_REASON_AUTH_FAIL:
swapWifiMode();
break;
case WIFI_REASON_NO_AP_FOUND:
SystemConfig sys;
if(!config.getSystemConfig(sys) || sys.dataCollectionConsent == 0) {
swapWifiMode();
}
break;
}
break;
}
}
#endif