ESP8266 NodeMCU WiFi Network Scanner

ESP8266 NodeMCU Wi-Fi Scanner allows you to easily locate visible wireless networks and its corresponding information. This program obtains the network name (SSID), signal strength (RSSI) and MAC Address, security.

Wi-Fi Scanner is useful for normal access point users who need to find out the signal strength distribution for their wireless network at home, or choose a position for their access point for optimal signal quality.

Using Wi-Fi Scanner, you can evaluate the allocation of wireless networks by channel and select the least congested bandwidth for their access point, allowing them to increase their connection speed significantly.

wifi scan

Program for ESP8266 NodeMCU WiFi Network Scanner

Results of Above Program

Upload program in ESP8266 NodeMCU and open serial monitor with baud rate setting of 115200.

ESP8266 wifi network scanner

More on WiFi Scan Class Library

Scan class is represented in Arduino WiFi library by scanNetworks() function. Developers of esp8266 / Arduino core extend this functionality by additional methods and properties.

Scan Functions

Scan for Networks

Scanning for networks takes hundreds of milliseconds to complete. This may be done in a single run when we are triggering scan process, waiting for completion, and providing result – all by a single function WiFi.scanNetworks(). Another option is to split this into steps, each done by a separate function. This way we can execute other tasks while scanning is in progress. This is called asynchronous scanning.

Scan for available Wi-Fi networks in one run and return the number of networks that has been discovered.

WiFi.scanNetworks()

There is on overload of this function that accepts two optional parameters to provide extended functionality of asynchronous scanning as well as looking for hidden networks.

WiFi.scanNetworks(async, show_hidden)

Both function parameters are of boolean type. They provide the flowing functionality:

  • asysnc – if set to true then scanning will start in background and function will exit without waiting for result. To check for result use separate function scanComplete that is described below.
  • show_hidden – set it to true to include in scan result networks with hidden SSID.

WiFi.scanComplete()

Check for result of asynchronous scanning. On scan completion function returns the number of discovered networks.

If scan is not done, then returned value is < 0 as follows:

  • Scanning still in progress: -1
  • Scanning has not been triggered: -2

WiFi.scanDelete()

Delete the last scan result from memory.

WiFi.scanNetworksAsync(onComplete, show_hidden)

Start scanning for available Wi-Fi networks. On completion execute another function.

Function parameters:

  • onComplete – the event handler executed when the scan is done
  • show_hidden – optional boolean parameter, set it to true to scan for hidden networks

Scan Results

Functions below provide access to result of scanning. It does not matter if scanning has been done in synchronous or asynchronous mode, scan results are available using the same API.

Individual results are accessible by providing a `networkItem’ that identifies the index (zero based) of discovered network.

WiFi.SSID(networkItem)

Return the SSID of a network discovered during the scan. Returned SSID is of the String type. The networkItem is a zero based index of network discovered during scan.

WiFi.encryptionType(networkItem)

Return the encryption type of a network discovered during the scan.

Function returns a number that encodes encryption type as follows:

  • 5 : ENC_TYPE_WEP – WEP
  • 2 : ENC_TYPE_TKIP – WPA / PSK
  • 4 : ENC_TYPE_CCMP – WPA2 / PSK
  • 7 : ENC_TYPE_NONE – open network
  • 8 : ENC_TYPE_AUTO – WPA / WPA2 / PSK

WiFi.RSSI(networkItem)
Return the RSSI (Received Signal Strength Indication) of a network discovered during the scan.

Returned RSSI is of the int32_t type. The networkItem is a zero based index of network discovered during scan.

WiFi.BSSIDstr(networkItem)

Return the BSSID string (Basic Service Set Identification) that is another name of MAC address of a network discovered during the scan.

WiFi.channel(networkItem)

Return the channel of a network discovered during the scan.

Returned channel is of the int32_t type. The networkItem is a zero based index of network discovered during scan.

WiFi.isHidden(networkItem)

Return information if a network discovered during the scan is hidden or not.

Returned value if the bolean type, and true means that network is hidden. The networkItem is a zero based index of network discovered during scan.

Leave a Reply