ScanNetworks only for WiFi Link firmware

Description

This example prints the board MAC address  and scans the available WiFi networks, using the WiFi Link library on the Arduino UNO WiFi.

Warning:
Use the Arduino IDE 1.8.x  and import the WiFi Link library using the Library Manager.

WiFi Link library

Hardware


Circuit

Connect the board to PC

UNOWiFi

Code

Upload the code below, using the Arduino IDE.


Note:
Make sure that the board uses the WiFi Link firmware.

/*

This example prints the board MAC address, and
scans for available Wifi networks.
Every ten seconds, it scans again. It doesn't actually
connect to any network, so no encryption scheme is specified.

Circuit:
* Arduino Primo or STAR OTTO or Uno WiFi Developer Edition (with WiFi Link firmware running)

created 13 July 2010
by dlf (Metodo2 srl)
modified 21 Junn 2012
by Tom Igoe and Jaymes Dec
modified 10 March 2017
by Sergio Tomasello and Andrea Cannistrá
*/

#include <WiFiLink.h>

void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

//Check if communication with the wifi module has been established
if (WiFi.status() == WL_NO_WIFI_MODULE_COMM) {
Serial.println("Communication with WiFi module not established.");
while (true); // don't continue:
}

// Print WiFi MAC address:
printMacAddress();

// scan for existing networks:
Serial.println("Scanning available networks...");
listNetworks();
}

void loop() {
delay(10000);
// scan for existing networks:
Serial.println("Scanning available networks...");
listNetworks();
}

void printMacAddress() {
// the MAC address of your Wifi shield
byte mac[6];

// print your MAC address:
WiFi.macAddress(mac);
Serial.print("MAC: ");
Serial.print(mac[5], HEX);
Serial.print(":");
Serial.print(mac[4], HEX);
Serial.print(":");
Serial.print(mac[3], HEX);
Serial.print(":");
Serial.print(mac[2], HEX);
Serial.print(":");
Serial.print(mac[1], HEX);
Serial.print(":");
Serial.println(mac[0], HEX);
}

void listNetworks() {
// scan for nearby networks:
Serial.println("** Scan Networks **");
int numSsid = WiFi.scanNetworks();
if (numSsid == -1)
{
Serial.println("Couldn't get a wifi connection");
while (true);
}

// print the list of networks seen:
Serial.print("number of available networks:");
Serial.println(numSsid);

// print the network number and name for each network found:
for (int thisNet = 0; thisNet < numSsid; thisNet++) {
Serial.print(thisNet);
Serial.print(") ");
Serial.print(WiFi.SSID(thisNet));
Serial.print("\tSignal: ");
Serial.print(WiFi.RSSI(thisNet));
Serial.print(" dBm");
Serial.print("\tEncryption: ");
printEncryptionType(WiFi.encryptionType(thisNet));
}
}

void printEncryptionType(int thisType) {
// read the encryption type and print out the name:
switch (thisType) {
case ENC_TYPE_WEP:
Serial.println("WEP");
break;
case ENC_TYPE_TKIP:
Serial.println("WPA");
break;
case ENC_TYPE_CCMP:
Serial.println("WPA2");
break;
case ENC_TYPE_NONE:
Serial.println("None");
break;
case ENC_TYPE_AUTO:
Serial.println("Auto");
break;
case ENC_TYPE_UNKNOW:
Serial.println("Unknown");
break;
}
}

Output

Open the Serial Monitor and check available networks :

ScanNetworks