Unify approach for presenting security modes across esp32 and esp8266

This commit is contained in:
Rick Watson
2018-11-11 18:24:59 +00:00
parent cc7acab37c
commit 83451e7d47
3 changed files with 43 additions and 15 deletions

View File

@ -26,7 +26,7 @@ void WiFiScanner::listNetworks(AsyncWebServerRequest *request) {
network["bssid"] = WiFi.BSSIDstr(i);
network["channel"] = WiFi.channel(i);
#if defined(ESP8266)
network["encryption_type"] = WiFi.encryptionType(i);
network["encryption_type"] = convertEncryptionType(WiFi.encryptionType(i));
#elif defined(ESP_PLATFORM)
network["encryption_type"] = (uint8_t) WiFi.encryptionType(i);
#endif
@ -39,3 +39,24 @@ void WiFiScanner::listNetworks(AsyncWebServerRequest *request) {
scanNetworks(request);
}
}
/*
* Convert encryption type to standard used by ESP32 rather than the translated form which the esp8266 libaries expose.
*
* This allows us to use a single set of mappings in the UI.
*/
uint8_t convertEncryptionType(uint8_t encryptionType){
switch (encryptionType){
case ENC_TYPE_NONE:
return AUTH_OPEN;
case ENC_TYPE_WEP:
return AUTH_WEP;
case ENC_TYPE_TKIP:
return AUTH_WPA_PSK;
case ENC_TYPE_CCMP:
return AUTH_WPA2_PSK;
case ENC_TYPE_AUTO:
return AUTH_WPA_WPA2_PSK;
}
return -1;
}

View File

@ -30,6 +30,10 @@ class WiFiScanner {
void scanNetworks(AsyncWebServerRequest *request);
void listNetworks(AsyncWebServerRequest *request);
#if defined(ESP8266)
uint8_t convertEncryptionType(uint8_t encryptionType);
#endif
};
#endif // end WiFiScanner_h