2012-06-06 11:28:21 +02:00
|
|
|
/*
|
2013-10-21 09:58:40 +02:00
|
|
|
|
|
|
|
This example connects to a WEP-encrypted Wifi network.
|
2012-06-06 11:28:21 +02:00
|
|
|
Then it prints the MAC address of the Wifi shield,
|
|
|
|
the IP address obtained, and other network details.
|
2013-10-21 09:58:40 +02:00
|
|
|
|
|
|
|
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,
|
2012-06-06 11:28:21 +02:00
|
|
|
all in the 0-9, A-F range.
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2012-06-06 11:28:21 +02:00
|
|
|
Circuit:
|
|
|
|
* WiFi shield attached
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2012-06-06 11:28:21 +02:00
|
|
|
created 13 July 2010
|
|
|
|
by dlf (Metodo2 srl)
|
|
|
|
modified 31 May 2012
|
|
|
|
by Tom Igoe
|
|
|
|
*/
|
2013-10-21 13:16:51 +02:00
|
|
|
#include <SPI.h>
|
2012-06-06 11:28:21 +02:00
|
|
|
#include <WiFi.h>
|
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
char ssid[] = "yourNetwork"; // your network SSID (name)
|
2012-06-06 11:28:21 +02:00
|
|
|
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() {
|
2012-06-06 17:31:14 +02:00
|
|
|
//Initialize serial and wait for port to open:
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.begin(9600);
|
2012-06-06 17:31:14 +02:00
|
|
|
while (!Serial) {
|
2015-09-21 14:44:19 +02:00
|
|
|
; // wait for serial port to connect. Needed for native USB port only
|
2012-06-06 17:31:14 +02:00
|
|
|
}
|
2012-06-06 11:28:21 +02:00
|
|
|
|
|
|
|
// check for the presence of the shield:
|
|
|
|
if (WiFi.status() == WL_NO_SHIELD) {
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.println("WiFi shield not present");
|
2012-06-06 11:28:21 +02:00
|
|
|
// don't continue:
|
2013-10-21 09:58:40 +02:00
|
|
|
while (true);
|
|
|
|
}
|
2012-06-06 11:28:21 +02:00
|
|
|
|
2013-07-19 16:34:44 +02:00
|
|
|
String fv = WiFi.firmwareVersion();
|
2015-07-06 15:18:33 +02:00
|
|
|
if (fv != "1.1.0") {
|
2013-07-19 16:34:44 +02:00
|
|
|
Serial.println("Please upgrade the firmware");
|
2015-07-06 15:18:33 +02:00
|
|
|
}
|
2013-07-19 16:34:44 +02:00
|
|
|
|
2012-06-06 11:28:21 +02:00
|
|
|
// attempt to connect to Wifi network:
|
2015-07-06 15:18:33 +02:00
|
|
|
while (status != WL_CONNECTED) {
|
2012-06-06 11:28:21 +02:00
|
|
|
Serial.print("Attempting to connect to WEP network, SSID: ");
|
|
|
|
Serial.println(ssid);
|
|
|
|
status = WiFi.begin(ssid, keyIndex, key);
|
|
|
|
|
|
|
|
// wait 10 seconds for connection:
|
|
|
|
delay(10000);
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2012-06-06 11:28:21 +02:00
|
|
|
// once you are connected :
|
|
|
|
Serial.print("You're connected to the network");
|
|
|
|
printCurrentNet();
|
|
|
|
printWifiData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
// check the network connection once every 10 seconds:
|
|
|
|
delay(10000);
|
|
|
|
printCurrentNet();
|
|
|
|
}
|
|
|
|
|
|
|
|
void printWifiData() {
|
|
|
|
// print your WiFi shield's IP address:
|
|
|
|
IPAddress ip = WiFi.localIP();
|
|
|
|
Serial.print("IP Address: ");
|
|
|
|
Serial.println(ip);
|
|
|
|
Serial.println(ip);
|
|
|
|
|
|
|
|
// print your MAC address:
|
2013-10-21 09:58:40 +02:00
|
|
|
byte mac[6];
|
2012-06-06 11:28:21 +02:00
|
|
|
WiFi.macAddress(mac);
|
|
|
|
Serial.print("MAC address: ");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(mac[5], HEX);
|
2012-06-06 11:28:21 +02:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(mac[4], HEX);
|
2012-06-06 11:28:21 +02:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(mac[3], HEX);
|
2012-06-06 11:28:21 +02:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(mac[2], HEX);
|
2012-06-06 11:28:21 +02:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(mac[1], HEX);
|
2012-06-06 11:28:21 +02:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.println(mac[0], HEX);
|
2012-06-06 11:28:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void printCurrentNet() {
|
|
|
|
// print the SSID of the network you're attached to:
|
|
|
|
Serial.print("SSID: ");
|
|
|
|
Serial.println(WiFi.SSID());
|
|
|
|
|
|
|
|
// print the MAC address of the router you're attached to:
|
|
|
|
byte bssid[6];
|
2013-10-21 09:58:40 +02:00
|
|
|
WiFi.BSSID(bssid);
|
2012-06-06 11:28:21 +02:00
|
|
|
Serial.print("BSSID: ");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(bssid[5], HEX);
|
2012-06-06 11:28:21 +02:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(bssid[4], HEX);
|
2012-06-06 11:28:21 +02:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(bssid[3], HEX);
|
2012-06-06 11:28:21 +02:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(bssid[2], HEX);
|
2012-06-06 11:28:21 +02:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(bssid[1], HEX);
|
2012-06-06 11:28:21 +02:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.println(bssid[0], HEX);
|
2012-06-06 11:28:21 +02:00
|
|
|
|
|
|
|
// print the received signal strength:
|
|
|
|
long rssi = WiFi.RSSI();
|
|
|
|
Serial.print("signal strength (RSSI):");
|
|
|
|
Serial.println(rssi);
|
|
|
|
|
|
|
|
// print the encryption type:
|
|
|
|
byte encryption = WiFi.encryptionType();
|
|
|
|
Serial.print("Encryption Type:");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.println(encryption, HEX);
|
2012-06-06 11:28:21 +02:00
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|