mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Updated Wifi Connect with WEP example to explain 40- vs 128-bit
This commit is contained in:
parent
15d7873d24
commit
0ddbfd0e95
@ -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 <WiFi.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user