From 7d3629302e3ee64160ec36aa2212a23ed29a5cb1 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Tue, 10 Jan 2012 08:46:46 -0500 Subject: [PATCH] Updated ScanNetworks examples to make sure scanning happened after wifi.Begin() --- .../ScanNetworksOpen/ScanNetworksOpen.ino | 9 +++--- .../ScanNetworksWPA/ScanNetworksWPA.ino | 29 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/WiFi/examples/ScanNetworksOpen/ScanNetworksOpen.ino b/WiFi/examples/ScanNetworksOpen/ScanNetworksOpen.ino index 3e5f07534..155a263b9 100644 --- a/WiFi/examples/ScanNetworksOpen/ScanNetworksOpen.ino +++ b/WiFi/examples/ScanNetworksOpen/ScanNetworksOpen.ino @@ -8,7 +8,7 @@ created 13 July 2010 by dlf (Metodo2 srl) - modified 15 Sep 2011 + modified 10 Jan 2012 by Tom Igoe */ @@ -28,13 +28,14 @@ void setup() { // initialize serial: Serial.begin(9600); - // scan for existing networks: - Serial.println("Scanning available networks..."); - scanNetworks(); // attempt to connect using WEP encryption: Serial.println("Attempting to connect to open network..."); status = WiFi.begin(ssid); + + // scan for existing networks: + Serial.println("Scanning available networks..."); + scanNetworks(); Serial.print("SSID: "); Serial.println(ssid); diff --git a/WiFi/examples/ScanNetworksWPA/ScanNetworksWPA.ino b/WiFi/examples/ScanNetworksWPA/ScanNetworksWPA.ino index d209888a4..d811842f7 100644 --- a/WiFi/examples/ScanNetworksWPA/ScanNetworksWPA.ino +++ b/WiFi/examples/ScanNetworksWPA/ScanNetworksWPA.ino @@ -8,7 +8,7 @@ created 13 July 2010 by dlf (Metodo2 srl) - modified 15 Sep 2011 + modified 10 Jan 2012 by Tom Igoe */ @@ -16,8 +16,8 @@ #include #include -char ssid[] = "yourNetwork"; // your network SSID (name) -char pass[] = "secretPassword"; // your network password +char ssid[] = "networkName"; // your network SSID (name) +char pass[] = "yourPassword"; // your network password int status = WL_IDLE_STATUS; // the Wifi radio's status byte mac[6]; // the MAC address of your Wifi shield @@ -28,20 +28,19 @@ IPAddress subnet; // the subnet mask void setup() { // initialize serial: Serial.begin(9600); - // scan for existing networks: - Serial.println("Scanning available networks..."); - //WiFi.begin(); - scanNetworks(); - + // attempt to connect using WEP encryption: -// Serial.println("Attempting to connect to WEP-128 network..."); -// status = WiFi.begin(ssid, keyIndex, key); - - // attempt to connect using WPA2 encryption: + // Serial.println("Attempting to connect to WEP-128 network..."); + // status = WiFi.begin(ssid, keyIndex, key); + + // attempt to connect using WPA2 encryption: Serial.println("Attempting to connect to WPA network..."); status = WiFi.begin(ssid, pass); - + Serial.println("Scanning available networks..."); + // scan for existing networks: + scanNetworks(); + Serial.print("SSID: "); Serial.println(ssid); @@ -52,6 +51,7 @@ void setup() { } // if you are connected, print out info about the connection: else { + printIpData(); printCurrentNet(); } @@ -71,7 +71,7 @@ void printIpData() { subnet = WiFi.subnetMask(); Serial.print("NETMASK: "); Serial.println(subnet); - + // print your gateway address: gateway = WiFi.gatewayIP(); @@ -141,3 +141,4 @@ void scanNetworks() { Serial.println(WiFi.SSID(thisNet)); } } +