Peter Clement
Published

Wi-Fi Scan

Understanding the Wi-Fi Scan Sketch on the ESP-32

IntermediateProtip5,209
Wi-Fi Scan

Things used in this project

Hardware components

Espressif ESP 32
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

My WiFiScan

Arduino
Simplified Wi-Fi Scan Library
//Program to Scan for WiFi network on the ESP 32

/*    This Sketch is here to help you understand the complexity in the Original WiFiScan Sketch  ... @_carlos_dev   */

//Include the WiFi Library
#include "WiFi.h"

void setup() {
  // put your setup code here, to run once:

  Serial.begin(115200);

  //Set the WiFi Mode to Station Mode
  //Station Mode enables the esp-32 to connect to a Router or Hotspot
  WiFi.mode(WIFI_STA);

  //Disconnect the WiFi from any existing connection
  WiFi.disconnect();
  delay(100); //wait for 100 milliseconds

}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("**Start Scan**");

  //Scan for available WiFi Network and print the number of Network found
  int network = WiFi.scanNetworks();

  Serial.print("Number of Network : ");
  Serial.println(network);

  if (network == 0) {
    //If there is no WiFi Network Around
    Serial.println("No Networks Found");

  }  else {
    Serial.print(network);
    Serial.println(" Networks Found");

    //This FOR loop is used to print multiple Wifi Network on the Serial Monitor

    for (int i = 0; i < network; ++i) {
      //Reason  for Post Increment is to Increment the value then Assign it to "i"
      //Print the SSID (name) and RSSI (Signal Strenght)
      Serial.print(i + 1);
      Serial.print(":");
      //prints the Individual SSID
      Serial.print(WiFi.SSID(i));

      //prints the Signal Strenght
      Serial.println(WiFi.RSSI(i));

      //This line helps to display the Network Encryption Mode whether it's OPEN or has PASSWORD
      //The Tenary Operation checks the Wifi Encryption to see if its OPEN then perfoms commands
      Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? "   OPEN ":"   Password Required");
    }
  }

  Serial.println("    ");
  delay(100);

  Serial.println("**Scan Complete**");
  Serial.println("    ");

  //Wait for 2 seconds and Scans again
  delay(2000);

}

My WiFiScan

Credits

Peter Clement
7 projects • 7 followers
I'm a Student and a Developer and I work on both Hardware and Software related Projects, also a big Outdoor fan 😎 and loves cooking 😋
Contact

Comments

Please log in or sign up to comment.