Scan with pins set

This commit is contained in:
ladyada 2019-04-10 16:43:44 -04:00
parent d9f61877a8
commit 7343db6589

View file

@ -1,117 +1,130 @@
/* /*
This example prints the board's MAC address, and This example prints the board's MAC address, and
scans for available Wifi networks using the NINA module. scans for available Wifi networks using the NINA module.
Every ten seconds, it scans again. It doesn't actually Every ten seconds, it scans again. It doesn't actually
connect to any network, so no encryption scheme is specified. connect to any network, so no encryption scheme is specified.
Circuit: Circuit:
* Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) * Board with NINA firmware on it (In this case its an Adafruit AirLift)
created 13 July 2010 created 13 July 2010
by dlf (Metodo2 srl) by dlf (Metodo2 srl)
modified 21 Junn 2012 modified 21 Junn 2012
by Tom Igoe and Jaymes Dec by Tom Igoe and Jaymes Dec
*/ */
#include <SPI.h> #include <SPI.h>
#include <WiFiNINA.h> #include <WiFiNINA.h>
void setup() { // Configure the pins used for the ESP32 connection
//Initialize serial and wait for port to open: #define SPIWIFI SPI // The SPI port
Serial.begin(9600); #define SPIWIFI_SS 10 // Chip select pin
while (!Serial) { #define SPIWIFI_ACK 7 // a.k.a BUSY or READY pin
; // wait for serial port to connect. Needed for native USB port only #define ESP32_RESETN 5 // Reset pin
} #define ESP32_GPIO0 -1 // Not connected
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) { void setup() {
Serial.println("Communication with WiFi module failed!"); //Initialize serial and wait for port to open:
// don't continue Serial.begin(9600);
while (true); while (!Serial) {
} ; // wait for serial port to connect. Needed for native USB port only
}
String fv = WiFi.firmwareVersion();
if (fv < "1.0.0") { Serial.println("WiFi Scanning test");
Serial.println("Please upgrade the firmware");
} // Set up the pins!
WiFi.setPins(SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
// print your MAC address:
byte mac[6]; // check for the WiFi module:
WiFi.macAddress(mac); while (WiFi.status() == WL_NO_MODULE) {
Serial.print("MAC: "); Serial.println("Communication with WiFi module failed!");
printMacAddress(mac); // don't continue
} delay(1000);
}
void loop() {
// scan for existing networks: String fv = WiFi.firmwareVersion();
Serial.println("Scanning available networks..."); if (fv < "1.0.0") {
listNetworks(); Serial.println("Please upgrade the firmware");
delay(10000); }
}
// print your MAC address:
void listNetworks() { byte mac[6];
// scan for nearby networks: WiFi.macAddress(mac);
Serial.println("** Scan Networks **"); Serial.print("MAC: ");
int numSsid = WiFi.scanNetworks(); printMacAddress(mac);
if (numSsid == -1) { }
Serial.println("Couldn't get a wifi connection");
while (true); void loop() {
} // scan for existing networks:
Serial.println("Scanning available networks...");
// print the list of networks seen: listNetworks();
Serial.print("number of available networks:"); delay(10000);
Serial.println(numSsid); }
// print the network number and name for each network found: void listNetworks() {
for (int thisNet = 0; thisNet < numSsid; thisNet++) { // scan for nearby networks:
Serial.print(thisNet); Serial.println("** Scan Networks **");
Serial.print(") "); int numSsid = WiFi.scanNetworks();
Serial.print(WiFi.SSID(thisNet)); if (numSsid == -1) {
Serial.print("\tSignal: "); Serial.println("Couldn't get a wifi connection");
Serial.print(WiFi.RSSI(thisNet)); while (true);
Serial.print(" dBm"); }
Serial.print("\tEncryption: ");
printEncryptionType(WiFi.encryptionType(thisNet)); // print the list of networks seen:
} Serial.print("number of available networks:");
} Serial.println(numSsid);
void printEncryptionType(int thisType) { // print the network number and name for each network found:
// read the encryption type and print out the name: for (int thisNet = 0; thisNet < numSsid; thisNet++) {
switch (thisType) { Serial.print(thisNet);
case ENC_TYPE_WEP: Serial.print(") ");
Serial.println("WEP"); Serial.print(WiFi.SSID(thisNet));
break; Serial.print("\tSignal: ");
case ENC_TYPE_TKIP: Serial.print(WiFi.RSSI(thisNet));
Serial.println("WPA"); Serial.print(" dBm");
break; Serial.print("\tEncryption: ");
case ENC_TYPE_CCMP: printEncryptionType(WiFi.encryptionType(thisNet));
Serial.println("WPA2"); }
break; }
case ENC_TYPE_NONE:
Serial.println("None"); void printEncryptionType(int thisType) {
break; // read the encryption type and print out the name:
case ENC_TYPE_AUTO: switch (thisType) {
Serial.println("Auto"); case ENC_TYPE_WEP:
break; Serial.println("WEP");
case ENC_TYPE_UNKNOWN: break;
default: case ENC_TYPE_TKIP:
Serial.println("Unknown"); Serial.println("WPA");
break; break;
} case ENC_TYPE_CCMP:
} Serial.println("WPA2");
break;
case ENC_TYPE_NONE:
void printMacAddress(byte mac[]) { Serial.println("None");
for (int i = 5; i >= 0; i--) { break;
if (mac[i] < 16) { case ENC_TYPE_AUTO:
Serial.print("0"); Serial.println("Auto");
} break;
Serial.print(mac[i], HEX); case ENC_TYPE_UNKNOWN:
if (i > 0) { default:
Serial.print(":"); Serial.println("Unknown");
} break;
} }
Serial.println(); }
}
void printMacAddress(byte mac[]) {
for (int i = 5; i >= 0; i--) {
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
if (i > 0) {
Serial.print(":");
}
}
Serial.println();
}