From 0ddbfd0e9562835b41b69f249d909263eb4b3001 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Sun, 4 Mar 2012 15:14:12 -0500 Subject: [PATCH] Updated Wifi Connect with WEP example to explain 40- vs 128-bit --- .../ConnectWithWEP/ConnectWithWEP.ino | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino b/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino index 4cad6f085..77e3eb098 100644 --- a/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino +++ b/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino @@ -1,23 +1,33 @@ /* - This example connects to an unencrypted Wifi network. + This example connects to a WEP-encrypted Wifi network. Then it prints the MAC address of the Wifi shield, the IP address obtained, and other network details. - + + If you use 40-bit WEP, you need a key that is 10 characters long, + and the characters must be hexadecimal (0-9 or A-F). + e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work + (too short) and ABBAISDEAF won't work (I and S are not + hexadecimal characters). + + For 128-bit, you need a string that is 26 characters long. + D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters, + all in the 0-9, A-F range. + Circuit: * WiFi shield attached created 13 July 2010 by dlf (Metodo2 srl) - modified 29 Feb 2012 - by Scott Fitzgerald + modified 4 Mar 2012 + by Tom Igoe */ - #include +#include -char ssid[] = "YourNetwork"; // your network SSID (name) -char key[] = "725d223132"; // your network key -int keyIndex = 0; // your network key Index number -int status = WL_IDLE_STATUS; // the Wifi radio's status +char ssid[] = "yourNetwork"; // your network SSID (name) +char key[] = "D0D0DEADF00DABBADEAFBEADED"; // your network key +int keyIndex = 0; // your network key Index number +int status = WL_IDLE_STATUS; // the Wifi radio's status void setup() { // initialize serial: @@ -26,8 +36,8 @@ void setup() { // attempt to connect to an open network: Serial.print("Attempting to connect to WEP network: "); Serial.println(ssid); - status = WiFi.begin(ssid, pass, key); - + status = WiFi.begin(ssid, keyIndex, key); + // if you're not connected, stop here: if ( status != WL_CONNECTED) { Serial.println("Couldn't get a wifi connection"); @@ -35,9 +45,9 @@ void setup() { } // if you are connected : else { - Serial.print("You're connected to the network"); - printCurrentNet(); - printWifiData(); + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); } } @@ -52,7 +62,7 @@ void printWifiData() { IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); - + // print your MAC address: byte mac[6]; WiFi.macAddress(mac); @@ -103,3 +113,4 @@ void printCurrentNet() { Serial.println(); } +