mirror of
https://github.com/richonguzman/LoRa_APRS_iGate.git
synced 2026-10-30 18:41:58 +01:00
Wifi warning with bad password
This commit is contained in:
1 parent
90b18ef088
commit
e692ce2729
3 files changed
+31
-1
No files matched your search
@@ -43,9 +43,12 @@ private:
|
||||
|
||||
String _hostName = "";
|
||||
std::vector<WiFiNetwork> _wifiNetworks;
|
||||
volatile uint8_t _lastWiFiDisconnectReason = 0;
|
||||
String _wifiAuthFailSSID = "";
|
||||
|
||||
int _findWiFiNetworkIndex(const String& ssid) const;
|
||||
bool _connectWiFi(const WiFiNetwork& network);
|
||||
bool _isWiFiAuthFailure() const;
|
||||
void _processAPTimeout();
|
||||
void _onNetworkEvent(arduino_event_id_t event, arduino_event_info_t /*info*/);
|
||||
|
||||
@@ -75,6 +78,7 @@ public:
|
||||
bool disconnectWiFi();
|
||||
String getWiFiSSID() const;
|
||||
String getWiFiAPSSID() const;
|
||||
String getWiFiAuthFailSSID() const;
|
||||
IPAddress getWiFiIP() const;
|
||||
IPAddress getWiFiAPIP() const;
|
||||
wifi_mode_t getWiFiMode() const;
|
||||
|
||||
+20
-1
@@ -51,12 +51,14 @@ bool NetworkManager::_connectWiFi(const WiFiNetwork& network) {
|
||||
WiFi.mode(_wifiAPmode ? WIFI_AP_STA : WIFI_STA);
|
||||
|
||||
Serial.println("[NM] Attempting to connect to WiFi: " + network.ssid);
|
||||
_lastWiFiDisconnectReason = 0;
|
||||
WiFi.begin(network.ssid.c_str(), network.psk.c_str());
|
||||
|
||||
Serial.print("[NM] Connecting ");
|
||||
|
||||
int attempts = 0;
|
||||
while (!isWiFiConnected() && attempts < 10) {
|
||||
if (_lastWiFiDisconnectReason == WIFI_REASON_AUTH_FAIL) break;
|
||||
delay(500);
|
||||
#ifdef INTERNAL_LED_PIN
|
||||
digitalWrite(INTERNAL_LED_PIN,HIGH);
|
||||
@@ -72,10 +74,19 @@ bool NetworkManager::_connectWiFi(const WiFiNetwork& network) {
|
||||
|
||||
if (isWiFiConnected()) return true;
|
||||
|
||||
if (_isWiFiAuthFailure()) {
|
||||
Serial.println("[NM] Wrong WiFi password for SSID: " + network.ssid);
|
||||
if (_wifiAuthFailSSID.isEmpty()) _wifiAuthFailSSID = network.ssid;
|
||||
}
|
||||
Serial.println("[NM] Failed to connect to WiFi after " + String(attempts) + " attempts. SSID: " + network.ssid);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetworkManager::_isWiFiAuthFailure() const {
|
||||
uint8_t reason = _lastWiFiDisconnectReason;
|
||||
return reason == WIFI_REASON_AUTH_FAIL || reason == WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT || reason == WIFI_REASON_HANDSHAKE_TIMEOUT;
|
||||
}
|
||||
|
||||
void NetworkManager::_processAPTimeout() {
|
||||
if (!_wifiAPmode || _apTimeout == 0) {
|
||||
return;
|
||||
@@ -93,8 +104,11 @@ void NetworkManager::_processAPTimeout() {
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkManager::_onNetworkEvent(arduino_event_id_t event, arduino_event_info_t /*info*/) {
|
||||
void NetworkManager::_onNetworkEvent(arduino_event_id_t event, arduino_event_info_t info) {
|
||||
switch (event) {
|
||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
||||
_lastWiFiDisconnectReason = info.wifi_sta_disconnected.reason;
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_START:
|
||||
Serial.println("[NM] ETH Started");
|
||||
if (!_hostName.isEmpty()) {
|
||||
@@ -224,6 +238,7 @@ bool NetworkManager::connectWiFi() {
|
||||
if (_wifiNetworks.empty()) {
|
||||
return false;
|
||||
}
|
||||
_wifiAuthFailSSID = "";
|
||||
|
||||
for (size_t i = 0; i < _wifiNetworks.size(); i++) {
|
||||
disconnectWiFi();
|
||||
@@ -256,6 +271,10 @@ String NetworkManager::getWiFiAPSSID() const {
|
||||
return WiFi.softAPSSID();
|
||||
}
|
||||
|
||||
String NetworkManager::getWiFiAuthFailSSID() const {
|
||||
return _wifiAuthFailSSID;
|
||||
}
|
||||
|
||||
IPAddress NetworkManager::getWiFiIP() const {
|
||||
return WiFi.localIP();
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ extern uint32_t lastServerCheck;
|
||||
uint8_t wifiCounter = 0;
|
||||
uint32_t lastBackupDigiTime = millis();
|
||||
uint32_t lastWiFiCheck = 0;
|
||||
bool firstWiFiAttempt = true;
|
||||
|
||||
|
||||
namespace WIFI_Utils {
|
||||
@@ -108,6 +109,8 @@ namespace WIFI_Utils {
|
||||
|
||||
displayShow("", "Connecting to WiFi:", "", " loading ...", 0);
|
||||
networkManager->connectWiFi();
|
||||
bool showAuthError = firstWiFiAttempt;
|
||||
firstWiFiAttempt = false;
|
||||
|
||||
#ifdef INTERNAL_LED_PIN
|
||||
digitalWrite(INTERNAL_LED_PIN, LOW);
|
||||
@@ -120,6 +123,10 @@ namespace WIFI_Utils {
|
||||
displayShow("", " Connected!!", "" , " loading ...", 1000);
|
||||
} else {
|
||||
Serial.println("[WiFi] Not connected to WiFi!");
|
||||
String authFailSSID = networkManager->getWiFiAuthFailSSID();
|
||||
if (showAuthError && !authFailSSID.isEmpty()) {
|
||||
displayShow("", "SSID: " + authFailSSID.substring(0, 15), "Bad WiFi password", "Double check settings", 5000);
|
||||
}
|
||||
if (Config.wifiAutoAP.enabled) {
|
||||
Serial.println("Starting AP fallback...");
|
||||
displayShow("", " WiFi Not Connected!", "" , " loading ...", 1000);
|
||||
|
||||
Reference in new issue
Block a user