/* WiFiEsp example: ScanNetworks This example prints the Wifi shield's MAC address, and scans for available Wifi networks using the Wifi shield. Every ten seconds, it scans again. It doesn't actually connect to any network, so no encryption scheme is specified. For more details see: http://yaab-arduino.blogspot.com/p/wifiesp.html */ #include "WiFiEsp.h" void setup() { // initialize serial for debugging SerialUSB.begin(115200); // initialize serial for ESP module Serial.begin(115200); // initialize ESP module WiFi.init(&Serial); // Wait until you open the USB port while(!SerialUSB); // Aspetta che apri la porta USB // check for the presence of the shield if (WiFi.status() == WL_NO_SHIELD) { SerialUSB.println("WiFi shield not present"); // don't continue while (true); } // Print WiFi MAC address printMacAddress(); } void loop() { // scan for existing networks SerialUSB.println(); SerialUSB.println("Scanning available networks..."); listNetworks(); delay(10000); } void printMacAddress() { // get your MAC address byte mac[6]; WiFi.macAddress(mac); // print MAC address char buf[20]; sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]); SerialUSB.print("MAC address: "); SerialUSB.println(buf); } void listNetworks() { // scan for nearby networks int numSsid = WiFi.scanNetworks(); if (numSsid == -1) { SerialUSB.println("Couldn't get a wifi connection"); while (true); } // print the list of networks seen SerialUSB.print("Number of available networks:"); SerialUSB.println(numSsid); // print the network number and name for each network found for (int thisNet = 0; thisNet < numSsid; thisNet++) { SerialUSB.print(thisNet); SerialUSB.print(") "); SerialUSB.print(WiFi.SSID(thisNet)); SerialUSB.print("\tSignal: "); SerialUSB.print(WiFi.RSSI(thisNet)); SerialUSB.print(" dBm"); SerialUSB.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: SerialUSB.print("WEP"); break; case ENC_TYPE_WPA_PSK: SerialUSB.print("WPA_PSK"); break; case ENC_TYPE_WPA2_PSK: SerialUSB.print("WPA2_PSK"); break; case ENC_TYPE_WPA_WPA2_PSK: SerialUSB.print("WPA_WPA2_PSK"); break; case ENC_TYPE_NONE: SerialUSB.print("None"); break; } SerialUSB.println(); }