From 8ebbe52bca5ab5824db40e8e9d579cf7b18f86f4 Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Thu, 3 Jun 2021 22:13:28 -1000 Subject: [PATCH] Tidier Wifi connection messages --- Grbl_Esp32/src/WebUI/WifiConfig.cpp | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/Grbl_Esp32/src/WebUI/WifiConfig.cpp b/Grbl_Esp32/src/WebUI/WifiConfig.cpp index 76e9af04..eb9ee488 100644 --- a/Grbl_Esp32/src/WebUI/WifiConfig.cpp +++ b/Grbl_Esp32/src/WebUI/WifiConfig.cpp @@ -211,10 +211,9 @@ namespace WebUI { void WiFiConfig::WiFiEvent(WiFiEvent_t event) { switch (event) { case SYSTEM_EVENT_STA_GOT_IP: - info_all("Connected with %s", WiFi.localIP().toString().c_str()); break; case SYSTEM_EVENT_STA_DISCONNECTED: - info_all("Disconnected"); + info_all("WiFi Disconnected"); break; default: break; @@ -239,12 +238,11 @@ namespace WebUI { */ bool WiFiConfig::ConnectSTA2AP() { - String msg, msg_out; - uint8_t count = 0; - uint8_t dot = 0; - wl_status_t status = WiFi.status(); - while (status != WL_CONNECTED && count < 40) { - switch (status) { + String msg, msg_out; + uint8_t count; + uint8_t dot = 0; + for (count = 0; count < 10; ++count) { + switch (WiFi.status()) { case WL_NO_SSID_AVAIL: info_all("No SSID"); return false; @@ -252,7 +250,8 @@ namespace WebUI { info_all("Connection failed"); return false; case WL_CONNECTED: - break; + info_all("Connected - IP is %s", WiFi.localIP().toString().c_str()); + return true; default: if ((dot > 3) || (dot == 0)) { dot = 0; @@ -264,11 +263,9 @@ namespace WebUI { break; } info_all(msg.c_str()); - COMMANDS::wait(1000); - count++; - status = WiFi.status(); + COMMANDS::wait(2000); } - return status == WL_CONNECTED; + return false; } /* @@ -317,11 +314,7 @@ namespace WebUI { } if (WiFi.begin(SSID.c_str(), (password.length() > 0) ? password.c_str() : NULL)) { - bool connected = ConnectSTA2AP(); - if (connected) { - info_all("STA IP %s", WiFi.localIP().toString().c_str()); - } - return connected; + return ConnectSTA2AP(); } info_serial("Cannot connect to %s", config->_comms->_staConfig->_ssid.c_str()); return false;