Have a Question?
Table of Contents
< All Topics
Print

302 Configuring WiFi on an ESP8266 or ESP32

Looking for a good way to check if your ESP8266 is working? Scanning for nearby WiFi networks is an excellent way to test.

Here is the code to do just that:

/*
* This sketch demonstrates how to scan WiFi networks.
* The API is almost the same as with the WiFi Shield library,
* the most obvious difference being the different file you need to include:
*/
#include "ESP8266WiFi.h"

void setup() {
Serial.begin(115200);

// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);

Serial.println("Setup done");
}

void loop() {
Serial.println("scan start");

// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
Serial.println("scan done");
if (n == 0)
Serial.println("no networks found");
else
{
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i &amp;amp;lt; n; ++i)
{
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
delay(10);
}
}
Serial.println("");

// Wait a bit before scanning again
delay(5000);
}

Here are the steps I took to make this work.

  1. Setup your board information in the tool menu to the correct settings.  I am using a Uctronics ESP8266 board included with the Kit I picked up on Amazon.
    Configuration settings for the Uctronics ESP8266 Arduino clone board
    Configuration settings for the Uctronics ESP8266 Arduino clone board
    Note: Your serial port may be different than mine.
    • Once you get that set, copy and paste the code to the IDE
    • Press the Upload button and wait for it to compile and upload the code
    • Go to the Serial Monitor from the Tools menu and check out the WiFi networks near you.
      Uctronics ESP8266 WiFi Scan Results
      Uctronics ESP8266 WiFi Scan Results

    This is a great little test to make sure your board is working. It tests the following:

    • Your Arduino IDE can talk to your board
    • Your board is working
    • You have more WiFi networks in your area than your thought.