Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve WiFi logging #358

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/network/wifihandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void WiFiNetwork::setUp() {
WiFi.setPhyMode(WIFI_PHY_MODE_11N);
#endif
WiFi.hostname("SlimeVR FBT Tracker");
wifiHandlerLogger.info("Loaded credentials for SSID %s and pass length %d", WiFi.SSID().c_str(), WiFi.psk().length());
wifiHandlerLogger.info("Loaded credentials for SSID '%s' and pass length %d", WiFi.SSID().c_str(), WiFi.psk().length());
setStaticIPIfDefined();
wl_status_t status = WiFi.begin(); // Should connect to last used access point, see https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html#begin
wifiHandlerLogger.debug("Status: %d", status);
Expand Down Expand Up @@ -126,7 +126,7 @@ void onConnected() {
statusManager.setStatus(SlimeVR::Status::WIFI_CONNECTING, false);
isWifiConnected = true;
hadWifi = true;
wifiHandlerLogger.info("Connected successfully to SSID '%s', ip address %s", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
wifiHandlerLogger.info("Connected successfully to SSID '%s', IP address %s", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
}

uint8_t WiFiNetwork::getWiFiState() {
Expand Down
48 changes: 45 additions & 3 deletions src/serial/serialcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace SerialCommands {
}

WiFiNetwork::setWiFiCredentials(sc_ssid, sc_pw);
logger.info("CMD SET WIFI OK: New wifi credentials set, reconnecting");
logger.info("CMD SET WIFI OK: New WiFi credentials set, reconnecting");
}
} else if (parser->equalCmdParam(1, "BWIFI")) {
if(parser->getParamCount() < 3) {
Expand Down Expand Up @@ -151,6 +151,48 @@ namespace SerialCommands {
);
}

#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;
Expand Down Expand Up @@ -248,9 +290,9 @@ namespace SerialCommands {
if (scanRes >= 0) {
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",
logger.info("[WSCAN] %d: %02d '%s' (%d dBm) %s",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the original reason for the usages of \t and no ' or is because it simplified parsing as the only people that would be able to input tab in their SSID would be people that know what the hell they are doing, a ' or a could easily be put on the SSID and break parsing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to tabs now, the ' can be considered to always surround the SSID and be trimmed (and/or use the length printed before)

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();
Expand Down