Skip to content

Instantly share code, notes, and snippets.


m1cr0lab/esp32-wifi-finder.cpp Secret

Last active Feb 14, 2021
What would you like to do?
A snippet to find a specific WiFi network with ESP32
* This piece of code follows a question about the article posted by Sara & Rui:
* ESP32 Useful Wi-Fi Library Functions (Arduino IDE)
* @see
* 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
* Here is a simple solution...
#include <Arduino.h>
#include <WiFi.h>
const char * SPECIFIC_SSID = "MyNetwork";
const char * ENCRYPTION_TYPE[] = {
struct WiFiInfo {
bool found;
int32_t channel;
int32_t rssi;
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) {
if (strcmp(WiFi.SSID(i).c_str(), ssid) == 0) {
info->found = true;
info->channel =;
info->rssi = WiFi.RSSI(i);
info->auth_mode = WiFi.encryptionType(i);
void setup() {
findWiFi(SPECIFIC_SSID, &wifi_info);
? "SSID: %s, channel: %i, RSSI: %i dBm, encryption: %s\n"
: "SSID: %s ... could not be found\n",
void loop() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment