1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-10 21:24:12 +01:00

Updated ScanNetworks examples to make sure scanning happened after wifi.Begin()

This commit is contained in:
Tom Igoe 2012-01-10 08:46:46 -05:00
parent 301c1d71d8
commit 7d3629302e
2 changed files with 20 additions and 18 deletions

View File

@ -8,7 +8,7 @@
created 13 July 2010 created 13 July 2010
by dlf (Metodo2 srl) by dlf (Metodo2 srl)
modified 15 Sep 2011 modified 10 Jan 2012
by Tom Igoe by Tom Igoe
*/ */
@ -28,14 +28,15 @@ void setup() {
// initialize serial: // initialize serial:
Serial.begin(9600); Serial.begin(9600);
// scan for existing networks:
Serial.println("Scanning available networks...");
scanNetworks();
// attempt to connect using WEP encryption: // attempt to connect using WEP encryption:
Serial.println("Attempting to connect to open network..."); Serial.println("Attempting to connect to open network...");
status = WiFi.begin(ssid); status = WiFi.begin(ssid);
// scan for existing networks:
Serial.println("Scanning available networks...");
scanNetworks();
Serial.print("SSID: "); Serial.print("SSID: ");
Serial.println(ssid); Serial.println(ssid);

View File

@ -8,7 +8,7 @@
created 13 July 2010 created 13 July 2010
by dlf (Metodo2 srl) by dlf (Metodo2 srl)
modified 15 Sep 2011 modified 10 Jan 2012
by Tom Igoe by Tom Igoe
*/ */
@ -16,8 +16,8 @@
#include <SPI.h> #include <SPI.h>
#include <WiFi.h> #include <WiFi.h>
char ssid[] = "yourNetwork"; // your network SSID (name) char ssid[] = "networkName"; // your network SSID (name)
char pass[] = "secretPassword"; // your network password char pass[] = "yourPassword"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status int status = WL_IDLE_STATUS; // the Wifi radio's status
byte mac[6]; // the MAC address of your Wifi shield byte mac[6]; // the MAC address of your Wifi shield
@ -28,19 +28,18 @@ IPAddress subnet; // the subnet mask
void setup() { void setup() {
// initialize serial: // initialize serial:
Serial.begin(9600); Serial.begin(9600);
// scan for existing networks:
Serial.println("Scanning available networks...");
//WiFi.begin();
scanNetworks();
// attempt to connect using WEP encryption: // attempt to connect using WEP encryption:
// Serial.println("Attempting to connect to WEP-128 network..."); // Serial.println("Attempting to connect to WEP-128 network...");
// status = WiFi.begin(ssid, keyIndex, key); // status = WiFi.begin(ssid, keyIndex, key);
// attempt to connect using WPA2 encryption: // attempt to connect using WPA2 encryption:
Serial.println("Attempting to connect to WPA network..."); Serial.println("Attempting to connect to WPA network...");
status = WiFi.begin(ssid, pass); status = WiFi.begin(ssid, pass);
Serial.println("Scanning available networks...");
// scan for existing networks:
scanNetworks();
Serial.print("SSID: "); Serial.print("SSID: ");
Serial.println(ssid); Serial.println(ssid);
@ -52,6 +51,7 @@ void setup() {
} }
// if you are connected, print out info about the connection: // if you are connected, print out info about the connection:
else { else {
printIpData(); printIpData();
printCurrentNet(); printCurrentNet();
} }
@ -141,3 +141,4 @@ void scanNetworks() {
Serial.println(WiFi.SSID(thisNet)); Serial.println(WiFi.SSID(thisNet));
} }
} }