/esp32-wifi-finder.cpp Secret
Last active
April 22, 2021 19:13
Revisions
-
m1cr0lab revised this gist
Feb 14, 2021 . 1 changed file with 20 additions and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,25 @@ /** * This piece of code follows a question about the article posted by Sara & Rui: * * ESP32 Useful Wi-Fi Library Functions (Arduino IDE) * @see https://randomnerdtutorials.com/esp32-useful-wi-fi-functions-arduino/ * * Here is Jim's question: * * Is there a way to quickly do a WiFi Scan for a SPECIFIC SSID and, * when it detects the WiFi SSID is available (or not), * does something with this information in the sketch? * * @see https://randomnerdtutorials.com/esp32-useful-wi-fi-functions-arduino/#comment-555652 * * Here is a simple solution... */ #include <Arduino.h> #include <WiFi.h> const char * SPECIFIC_SSID = "MyNetwork"; const char * ENCRYPTION_TYPE[] = { "Open", "WEP", "WPA-PSK", @@ -42,7 +59,7 @@ void setup() { SPECIFIC_SSID, wifi_info.channel, wifi_info.rssi, ENCRYPTION_TYPE[wifi_info.auth_mode]); } void loop() {} -
m1cr0lab revised this gist
Feb 13, 2021 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,14 @@ #include <Arduino.h> #include <WiFi.h> const char * SPECIFIC_SSID = "MyNetwork"; const char * ENC_TYPE[] = { "Open", "WEP", "WPA-PSK", "WPA2-PSK", "WPA-WPA2-PSK", "WPA2-Enterprise", "Unknown" }; @@ -19,7 +19,7 @@ struct WiFiInfo { wifi_auth_mode_t auth_mode; } wifi_info; void findWiFi(const char * const ssid, WiFiInfo * const info) { info->found = false; int16_t n = WiFi.scanNetworks(); for (uint8_t i=0; i<n; ++i) { -
m1cr0lab revised this gist
Feb 13, 2021 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,11 +5,11 @@ const char* SPECIFIC_SSID = "MyNetwork"; const char* ENC_TYPE[] = { "Open", "WEP", "WPA-PSK", "WPA2-PSK", "WPA-WPA2-PSK", "WPA2-ENTERPRISE", "Unknown" }; struct WiFiInfo { -
m1cr0lab revised this gist
Feb 13, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,7 @@ struct WiFiInfo { wifi_auth_mode_t auth_mode; } wifi_info; void findWiFi(const char* const ssid, WiFiInfo* const info) { info->found = false; int16_t n = WiFi.scanNetworks(); for (uint8_t i=0; i<n; ++i) { -
m1cr0lab revised this gist
Feb 13, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ #include <Arduino.h> #include <WiFi.h> const char* SPECIFIC_SSID = "MyNetwork"; const char* ENC_TYPE[] = { "Open", "WEP", @@ -19,7 +19,7 @@ struct WiFiInfo { wifi_auth_mode_t auth_mode; } wifi_info; void findWiFi(const char* ssid, WiFiInfo* const info) info->found = false; int16_t n = WiFi.scanNetworks(); for (uint8_t i=0; i<n; ++i) { -
m1cr0lab created this gist
Feb 13, 2021 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ #include <Arduino.h> #include <WiFi.h> const char* SPECIFIC_SSID = "YourNetwork"; const char* ENC_TYPE[] = { "Open", "WEP", "WPA_PSK", "WPA2_PSK", "WPA_WPA2_PSK", "WPA2_ENTERPRISE", "MAX" }; struct WiFiInfo { bool found; int32_t channel; int32_t rssi; wifi_auth_mode_t auth_mode; } wifi_info; void findWiFi(const char *ssid, WiFiInfo *info) { info->found = false; int16_t n = WiFi.scanNetworks(); for (uint8_t i=0; i<n; ++i) { if (strcmp(WiFi.SSID(i).c_str(), ssid) == 0) { info->found = true; info->channel = WiFi.channel(i); info->rssi = WiFi.RSSI(i); info->auth_mode = WiFi.encryptionType(i); return; } } } void setup() { Serial.begin(115200); findWiFi(SPECIFIC_SSID, &wifi_info); Serial.printf(wifi_info.found ? "SSID: %s, channel: %i, RSSI: %i dBm, encryption: %s\n" : "SSID: %s ... could not be found\n", SPECIFIC_SSID, wifi_info.channel, wifi_info.rssi, ENC_TYPE[wifi_info.auth_mode]); } void loop() {}