From da4480315b275582646cac5c4a04031c724f4f8e Mon Sep 17 00:00:00 2001 From: Butterscotch! Date: Wed, 11 Dec 2024 10:33:57 -0500 Subject: [PATCH] Improve WiFi logging (#358) * Try to make WiFi printout more standard * Handle ESP8266 WiFi encryption type ESP8266 WiFi encryption type is according to 802.11, while ESP32 seems to report based on whatever... It would also be oh so convenient if we just report the name, so here it is * Use tabs with quotes for WiFi scan It was mentioned this would be easier for parsing, so I'll just leave it the same but with quotes, as it's still just as readable now * Reformat with clang-format --- src/network/wifihandler.cpp | 4 +-- src/serial/serialcommands.cpp | 46 +++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/network/wifihandler.cpp b/src/network/wifihandler.cpp index 2bf2984e..b2581384 100644 --- a/src/network/wifihandler.cpp +++ b/src/network/wifihandler.cpp @@ -79,7 +79,7 @@ void WiFiNetwork::setUp() { #endif WiFi.hostname("SlimeVR FBT Tracker"); wifiHandlerLogger.info( - "Loaded credentials for SSID %s and pass length %d", + "Loaded credentials for SSID '%s' and pass length %d", WiFi.SSID().c_str(), WiFi.psk().length() ); @@ -127,7 +127,7 @@ void onConnected() { isWifiConnected = true; hadWifi = true; wifiHandlerLogger.info( - "Connected successfully to SSID '%s', ip address %s", + "Connected successfully to SSID '%s', IP address %s", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str() ); diff --git a/src/serial/serialcommands.cpp b/src/serial/serialcommands.cpp index 84f1fc09..4466e5c2 100644 --- a/src/serial/serialcommands.cpp +++ b/src/serial/serialcommands.cpp @@ -172,6 +172,48 @@ void printState() { ); } +#if ESP32 +char* getEncryptionTypeName(wifi_auth_mode_t type) { + switch (type) { + case WIFI_AUTH_OPEN: + return "OPEN"; + case WIFI_AUTH_WEP: + return "WEP"; + case WIFI_AUTH_WPA_PSK: + return "WPA_PSK"; + case WIFI_AUTH_WPA2_PSK: + return "WPA2_PSK"; + case WIFI_AUTH_WPA_WPA2_PSK: + return "WPA_WPA2_PSK"; + case WIFI_AUTH_WPA2_ENTERPRISE: + return "WPA2_ENTERPRISE"; + case WIFI_AUTH_WPA3_PSK: + return "WPA3_PSK"; + case WIFI_AUTH_WPA2_WPA3_PSK: + return "WPA2_WPA3_PSK"; + case WIFI_AUTH_WAPI_PSK: + return "WAPI_PSK"; + case WIFI_AUTH_WPA3_ENT_192: + return "WPA3_ENT_192"; + } +#else +char* getEncryptionTypeName(uint8_t type) { + switch (type) { + case ENC_TYPE_NONE: + return "OPEN"; + case ENC_TYPE_WEP: + return "WEP"; + case ENC_TYPE_TKIP: + return "WPA_PSK"; + case ENC_TYPE_CCMP: + return "WPA2_PSK"; + case ENC_TYPE_AUTO: + return "WPA_WPA2_PSK"; + } +#endif + return "UNKNOWN"; +} + void cmdGet(CmdParser* parser) { if (parser->getParamCount() < 2) { return; @@ -271,12 +313,12 @@ void cmdGet(CmdParser* parser) { logger.info("[WSCAN] Found %d networks:", scanRes); for (int i = 0; i < scanRes; i++) { logger.info( - "[WSCAN] %d:\t%02d\t%s\t(%d)\t%s", + "[WSCAN] %d:\t%02d\t'%s'\t(%d dBm)\t%s", i, WiFi.SSID(i).length(), WiFi.SSID(i).c_str(), WiFi.RSSI(i), - ((WiFi.encryptionType(i) == 0) ? "OPEN" : "PASSWD") + getEncryptionTypeName(WiFi.encryptionType(i)) ); } WiFi.scanDelete();