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

@ -1,23 +1,26 @@
export const WIFI_SECURITY_WPA_TKIP = 2; export const WIFI_AUTH_OPEN = 0;
export const WIFI_SECURITY_WEP = 5; export const WIFI_AUTH_WEP = 1;
export const WIFI_SECURITY_WPA_CCMP = 4; export const WIFI_AUTH_WEP_PSK = 2;
export const WIFI_SECURITY_NONE = 7; export const WIFI_AUTH_WEP2_PSK = 3;
export const WIFI_SECURITY_AUTO = 8; export const WIFI_AUTH_WPA_WPA2_PSK = 4;
export const WIFI_AUTH_WPA2_ENTERPRISE = 5;
export const isNetworkOpen = selectedNetwork => selectedNetwork && selectedNetwork.encryption_type === WIFI_SECURITY_NONE; export const isNetworkOpen = selectedNetwork => selectedNetwork && selectedNetwork.encryption_type === WIFI_AUTH_OPEN;
export const networkSecurityMode = selectedNetwork => { export const networkSecurityMode = selectedNetwork => {
switch (selectedNetwork.encryption_type){ switch (selectedNetwork.encryption_type){
case WIFI_SECURITY_WPA_TKIP: case WIFI_AUTH_WEP:
case WIFI_SECURITY_WPA_CCMP: case WIFI_AUTH_WEP_PSK:
return "WPA";
case WIFI_SECURITY_WEP:
return "WEP"; return "WEP";
case WIFI_SECURITY_AUTO: case WIFI_AUTH_WEP2_PSK:
return "Auto"; return "WEP2";
case WIFI_SECURITY_NONE: case WIFI_AUTH_WPA_WPA2_PSK:
return "WPA/WEP2";
case WIFI_AUTH_WPA2_ENTERPRISE:
return "WEP2 Enterprise";
case WIFI_AUTH_OPEN:
return "None"; return "None";
default: default:
return "Unknown"; return "Unknown";
} }
} }

View File

@ -26,7 +26,7 @@ void WiFiScanner::listNetworks(AsyncWebServerRequest *request) {
network["bssid"] = WiFi.BSSIDstr(i); network["bssid"] = WiFi.BSSIDstr(i);
network["channel"] = WiFi.channel(i); network["channel"] = WiFi.channel(i);
#if defined(ESP8266) #if defined(ESP8266)
network["encryption_type"] = WiFi.encryptionType(i); network["encryption_type"] = convertEncryptionType(WiFi.encryptionType(i));
#elif defined(ESP_PLATFORM) #elif defined(ESP_PLATFORM)
network["encryption_type"] = (uint8_t) WiFi.encryptionType(i); network["encryption_type"] = (uint8_t) WiFi.encryptionType(i);
#endif #endif
@ -39,3 +39,24 @@ void WiFiScanner::listNetworks(AsyncWebServerRequest *request) {
scanNetworks(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 scanNetworks(AsyncWebServerRequest *request);
void listNetworks(AsyncWebServerRequest *request); void listNetworks(AsyncWebServerRequest *request);
#if defined(ESP8266)
uint8_t convertEncryptionType(uint8_t encryptionType);
#endif
}; };
#endif // end WiFiScanner_h #endif // end WiFiScanner_h