ESP8266: Scanning WiFi Networks

The objective of this post is to explain how to scan the surrounding WiFi networks with the ESP8266.

The code

The code for this tutorial will be very simple and since we only want to scan and get some information about the surrounding WiFi networks, we will do all the coding on the setup function. So, we will leave the main loop empty.

First of all, we include the ESP8266WiFi library, which will make available the functionality needed for the ESP8266 to interact with the WiFi networks. We can remember from previous posts that this is also the library needed for us to connect to a WiFi network.

#include "ESP8266WiFi.h"

In the setup function, we start by  opening a serial connection, so we can send the data to the Arduino IDE serial console.

Next, to scan the networks, we call the scanNetworks method on the WiFi object of the library we included. This method will return the number of networks discovered [1].

Note that this method can be called with two additional arguments, one that indicates the scanning should be done asynchronously, and another to show networks with hidden SSID [1]. More details about these functionalities can be found here.

int numberOfNetworks = WiFi.scanNetworks();

Now, to get each network SSID, we just need to call the SSID method, which receives as argument the index of one of the previously discovered networks. In the example bellow, we are getting this parameter for the first network of the list. Naturally, you should check first if any network was discovered


We can also get the RSSI (Received Signal Strength Indicator) of each network by calling the RSSI method on the WiFi object, again passing as input the index of the network.


The complete code is shown bellow, which includes the iteration over the discovered networks and printing of these indicators to the serial port.

#include "ESP8266WiFi.h"

void setup() {


  int numberOfNetworks = WiFi.scanNetworks();

  for(int i =0; i<numberOfNetworks; i++){

      Serial.print("Network name: ");
      Serial.print("Signal strength: ");



void loop() {}

To test the code just upload it to the ESP8266 and open the serial console. You should get something similar to figure 1.


Figure 1 – Output of the program.

Note that there are more functionalities associated with the scanning of surrounding WiFi networks, which can be seen here.

Related Posts

ESP8266: Connecting to a WiFi Network



Technical details

  • ESP8266 libraries: v2.3.0

5 Replies to “ESP8266: Scanning WiFi Networks”

    1. Hi! Did you select the correct baud rate on the serial monitor? It should be the same baud rate you used on the Serial.Begin call.

      You also need to confirm that the serial port you have selected is the same of the ESP. To do so, you can check how many serial ports are available with the ESP connected, then connect it and check the new one that should appear. That should be the one of your device.

      To help debugging, you can also do a much simpler program that just prints stuff to the serial port, to confirm that that way you can receive the data.

      Best regards,
      Nuno Santos

  1. Hi i am getting a problem with the WiFi.scanNetworks(). when i scan the networks i am getting random number of networks like 16 or 10 or so. While the actual networks are 27 or more. when i first scan i am getting randomly picked networks like 10 or 15. in the second scan other random picked networks are coming and the count of networks is also random like 10 or 20. So can you please help me with this problem.

    1. Hi!

      I never ran into that issue, so unfortunately I cannot be of much assistance.

      This is just a guess, but it may actually be related to the high number of networks present, maybe some problem with noise?

      I’m not sure if there is any limitation of the maximum number of networks the ESP can scan and show, my suggestion is that you ask around the GitHub page of the Arduino core. There someone may already faced the same issue and have some idea of what is happening.

      Let us know if you find a solution.

      Best regards,
      Nuno Santos

Leave a Reply