When working with ESP8266 we may need to be able to discover surrounding Wi-Fi networks.
This tutorial provides example how to scan the available Wi-Fi networks using ESP8266 NodeMCU development board.
Components
No. | Component | Quantity |
---|---|---|
1. | ESP8266 NodeMCU + Micro USB cable | 1 |
Code
In the setup
function we initialize serial communication at a baud rate of 9600. The scanNetworks
function of the WiFi
object allows to scan Wi-Fi networks. This function returns the number of discovered networks. To get SSID of each network, we can use WiFi.SSID
function and pass the index as the argument. The WiFi.RSSI
function returns the network signal strength. A value that is closer to zero means stronger signal.
#include <ESP8266WiFi.h>
void setup()
{
Serial.begin(9600);
int numberOfNetworks = WiFi.scanNetworks();
for (int i = 0; i < numberOfNetworks; i++) {
String networkName = WiFi.SSID(i);
int signalStrength = WiFi.RSSI(i);
Serial.println(networkName + " (" + signalStrength + ")");
}
}
void loop() {}
Leave a Comment
Cancel reply