WiFi scanner with ESP32

Use an ESP32 to get the best performance with your WiFi router.

For the best performance with your WiFi router, you should choose a wireless channel less used by any of your neighbors. Many routers use the same channel by default–e.g., 6–and unless you know to test for and change the Wi-Fi channel when you first install your router, you’re probably using the same channel as someone else nearby. In other words, decreased performance.

Here the script for the ESP32 to scan your neighborhood WiFi access points.
#include "WiFi.h"

void setup(){

void loop(){
  Serial.println("Start scan");
  int n = WiFi.scanNetworks();

  if (n == 0) {
    Serial.println("no networks found");
  } else {
    Serial.println(" networks found");
    for (int i = 0; i < n; ++i) {
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(" (");
      Serial.print(") ");
      Serial.print(" [");
      Serial.print("] ");
      String encryptionTypeDescription = translateEncryptionType(WiFi.encryptionType(i));
  Serial.println("Scan done");

String translateEncryptionType(wifi_auth_mode_t encryptionType) {
  switch (encryptionType) {
    case (0):
      return "Open";
    case (1):
      return "WEP";
    case (2):
      return "WPA_PSK";
    case (3):
      return "WPA2_PSK";
    case (4):
      return "WPA_WPA2_PSK";
    case (5):
      return "WPA2_ENTERPRISE";
      return "UNKOWN";

Here an example output from my neighborhood:

scan start
15 networks found
1: robnet2 (-54) [13] WPA2_PSK
2: woodfamily2 (-85) [2] WPA2_PSK
3: VGV7519DFC699 (-85) [6] WPA_WPA2_PSK
4: woodfamilyGuest (-86) [2] WPA2_PSK
5: FRITZ!Box 7581 MO (-87) [6] WPA2_PSK
6: Ziggo beneden (-89) [1] WPA2_PSK
7: Infinity (-89) [6] WPA_WPA2_PSK
8: Ziggo (-91) [1] WPA2_ENTERPRISE
9: Ziggo (-91) [11] WPA2_ENTERPRISE
10: Ziggo (-92) [1] WPA2_ENTERPRISE
11: Infinity (-92) [11] WPA2_PSK
12: FBI surveillance van (-93) [6] WPA_WPA2_PSK
13: Ziggo39330 (-94) [1] WPA2_PSK
14: Eightball's network (-94) [6] WPA2_PSK
15: DIRECT-8E-HP ENVY 4520 series (-96) [6] WPA2_PSK
scan done

Change the Wi-Fi Channel on Your Router

Once you know the wireless channel that’s least congested near you, head to your router’s administration page by typing in its IP address in the browser address bar. Depending on your router, this will likely be something like,, or (check your router manual or the bottom of your router for details).

Head to your router’s wireless settings to change the Wi-Fi channel and hit apply for it to take effect.

ESP32 HW-607

See also my other page using the ESP8266 / Wemos D1 Mini as WiFi scanner

3 thoughts on “WiFi scanner with ESP32”

  1. Hi, I tried your code hoping to scan all MAC addresses from surrounding WiFi access points.

    I always get the error :

    Using library WiFi at version 1.0 in folder: C:\Users\test\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.0\libraries\WiFi
    exit status 1
    enumeration value ‘WIFI_AUTH_MAX’ not handled in switch [-Werror=switch]

    Please help to fix this error.



    1. just add this to the end of the switch statement (after line 52):
      return “UNKOWN”;

  2. Thank you for this, I need to be able to list the available routers for a clock I’m building, otherwise it will have to rely on an RTC, which seems to drift faster than I want. This is exactly what i need to start showing the networks so the user can choose one and give the password, which will then be coded and go into the NVRAM.
    Works fine on DOIT ESP32 Devkit V1 with Arduino IDE ver 1.8.12

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.