#include "WiFi.h"
#define redLedPin 23
#define greenLedPin 22
#define blueLedPin 2
void setup() {
// put your setup code here, to run once:
pinMode(redLedPin,OUTPUT);
pinMode(blueLedPin,OUTPUT);
pinMode(greenLedPin,OUTPUT);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.disconnect(); //to disconnect existing wifi
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Scanning available networks...");
digitalWrite(redLedPin,HIGH);
digitalWrite(greenLedPin,HIGH);
int n=WiFi.scanNetworks(); // to see if there is any existing networks
if(n!=0){
digitalWrite(redLedPin,LOW);
digitalWrite(greenLedPin,HIGH);
Serial.println(n);Serial.println(" network(s) found ");
for(int i=0; i<n; ++i){ // now I want to display all the found networks name i,e SSID(networks name)
Serial.print("network "); Serial.print(i+1); Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" ("); Serial.print(WiFi.RSSI(i)); Serial.print(" )"); // RSSI means recieved signal strength
Serial.println((WiFi.encryptionType(i)== WIFI_AUTH_OPEN)? "open ": " ''' ");
delay(50);
}
}
else{
Serial.println("no available networks found");
digitalWrite(redLedPin,LOW);
digitalWrite(greenLedPin,LOW);
}
Serial.println("\n............................................\n");
delay(5000);
}