Skip to content

Commit

Permalink
Swap to AP mode if WiFi psk is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
gskjold committed Jun 11, 2023
1 parent 5b6b987 commit ca1c237
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/AmsToMqttBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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
Expand Down

0 comments on commit ca1c237

Please sign in to comment.