2012-03-02 19:31:48 +01:00
|
|
|
/*
|
2013-10-21 09:58:40 +02:00
|
|
|
|
|
|
|
This example connects to an unencrypted Wifi network.
|
2012-03-02 19:31:48 +01:00
|
|
|
Then it prints the MAC address of the Wifi shield,
|
|
|
|
the IP address obtained, and other network details.
|
|
|
|
|
|
|
|
Circuit:
|
|
|
|
* WiFi shield attached
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2012-03-02 19:31:48 +01:00
|
|
|
created 13 July 2010
|
|
|
|
by dlf (Metodo2 srl)
|
2012-05-31 18:16:14 +02:00
|
|
|
modified 31 May 2012
|
|
|
|
by Tom Igoe
|
2012-03-02 19:31:48 +01:00
|
|
|
*/
|
2013-10-21 13:16:51 +02:00
|
|
|
#include <SPI.h>
|
2013-10-21 09:58:40 +02:00
|
|
|
#include <WiFi.h>
|
2012-03-02 19:31:48 +01:00
|
|
|
|
|
|
|
char ssid[] = "yourNetwork"; // the name of your network
|
|
|
|
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) {
|
|
|
|
; // wait for serial port to connect. Needed for Leonardo only
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2012-05-31 18:16:14 +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-05-31 18:16:14 +02:00
|
|
|
// don't continue:
|
2013-10-21 09:58:40 +02:00
|
|
|
while (true);
|
|
|
|
}
|
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-10-21 09:58:40 +02:00
|
|
|
|
|
|
|
// attempt to connect to Wifi network:
|
2015-07-06 15:18:33 +02:00
|
|
|
while (status != WL_CONNECTED) {
|
2012-05-31 18:16:14 +02:00
|
|
|
Serial.print("Attempting to connect to open SSID: ");
|
|
|
|
Serial.println(ssid);
|
|
|
|
status = WiFi.begin(ssid);
|
|
|
|
|
|
|
|
// wait 10 seconds for connection:
|
|
|
|
delay(10000);
|
2012-03-02 19:31:48 +01:00
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2012-05-31 18:16:14 +02:00
|
|
|
// you're connected now, so print out the data:
|
|
|
|
Serial.print("You're connected to the network");
|
|
|
|
printCurrentNet();
|
|
|
|
printWifiData();
|
2012-03-02 19:31:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print("IP Address: ");
|
2012-03-04 23:19:24 +01:00
|
|
|
Serial.println(ip);
|
2012-03-02 19:31:48 +01:00
|
|
|
Serial.println(ip);
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2012-03-02 19:31:48 +01:00
|
|
|
// print your MAC address:
|
2013-10-21 09:58:40 +02:00
|
|
|
byte mac[6];
|
2012-03-02 19:31:48 +01:00
|
|
|
WiFi.macAddress(mac);
|
|
|
|
Serial.print("MAC address: ");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(mac[5], HEX);
|
2012-03-02 19:31:48 +01:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(mac[4], HEX);
|
2012-03-02 19:31:48 +01:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(mac[3], HEX);
|
2012-03-02 19:31:48 +01:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(mac[2], HEX);
|
2012-03-02 19:31:48 +01:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(mac[1], HEX);
|
2012-03-02 19:31:48 +01:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.println(mac[0], HEX);
|
|
|
|
|
2012-03-02 19:31:48 +01:00
|
|
|
// print your subnet mask:
|
|
|
|
IPAddress subnet = WiFi.subnetMask();
|
|
|
|
Serial.print("NetMask: ");
|
|
|
|
Serial.println(subnet);
|
|
|
|
|
|
|
|
// print your gateway address:
|
|
|
|
IPAddress gateway = WiFi.gatewayIP();
|
|
|
|
Serial.print("Gateway: ");
|
|
|
|
Serial.println(gateway);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-03-02 19:31:48 +01:00
|
|
|
Serial.print("BSSID: ");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(bssid[5], HEX);
|
2012-03-02 19:31:48 +01:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(bssid[4], HEX);
|
2012-03-02 19:31:48 +01:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(bssid[3], HEX);
|
2012-03-02 19:31:48 +01:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(bssid[2], HEX);
|
2012-03-02 19:31:48 +01:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.print(bssid[1], HEX);
|
2012-03-02 19:31:48 +01:00
|
|
|
Serial.print(":");
|
2013-10-21 09:58:40 +02:00
|
|
|
Serial.println(bssid[0], HEX);
|
2012-03-02 19:31:48 +01:00
|
|
|
|
|
|
|
// print the received signal strength:
|
|
|
|
long rssi = WiFi.RSSI();
|
2012-03-02 19:34:17 +01:00
|
|
|
Serial.print("signal strength (RSSI):");
|
2012-03-02 19:31:48 +01:00
|
|
|
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-03-02 19:31:48 +01:00
|
|
|
}
|
|
|
|
|