Skip to content

Commit 5dfafe7

Browse files
committed
WiFi Shield examples: added the firmware version check
1 parent b415903 commit 5dfafe7

File tree

13 files changed

+406
-362
lines changed

13 files changed

+406
-362
lines changed
Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,51 @@
11
/*
2-
3-
This example connects to an unencrypted Wifi network.
2+
3+
This example connects to an unencrypted Wifi network.
44
Then it prints the MAC address of the Wifi shield,
55
the IP address obtained, and other network details.
66
77
Circuit:
88
* WiFi shield attached
9-
9+
1010
created 13 July 2010
1111
by dlf (Metodo2 srl)
1212
modified 31 May 2012
1313
by Tom Igoe
1414
*/
15-
#include <WiFi.h>
15+
#include <SPI.h>
16+
#include <WiFi.h>
1617

1718
char ssid[] = "yourNetwork"; // the name of your network
1819
int status = WL_IDLE_STATUS; // the Wifi radio's status
1920

2021
void setup() {
2122
//Initialize serial and wait for port to open:
22-
Serial.begin(9600);
23+
Serial.begin(9600);
2324
while (!Serial) {
2425
; // wait for serial port to connect. Needed for Leonardo only
2526
}
26-
27+
2728
// check for the presence of the shield:
2829
if (WiFi.status() == WL_NO_SHIELD) {
29-
Serial.println("WiFi shield not present");
30+
Serial.println("WiFi shield not present");
3031
// don't continue:
31-
while(true);
32-
}
33-
34-
// attempt to connect to Wifi network:
35-
while ( status != WL_CONNECTED) {
32+
while (true);
33+
}
34+
35+
String fv = WiFi.firmwareVersion();
36+
if ( fv != "1.1.0" )
37+
Serial.println("Please upgrade the firmware");
38+
39+
// attempt to connect to Wifi network:
40+
while ( status != WL_CONNECTED) {
3641
Serial.print("Attempting to connect to open SSID: ");
3742
Serial.println(ssid);
3843
status = WiFi.begin(ssid);
3944

4045
// wait 10 seconds for connection:
4146
delay(10000);
4247
}
43-
48+
4449
// you're connected now, so print out the data:
4550
Serial.print("You're connected to the network");
4651
printCurrentNet();
@@ -56,26 +61,26 @@ void loop() {
5661
void printWifiData() {
5762
// print your WiFi shield's IP address:
5863
IPAddress ip = WiFi.localIP();
59-
Serial.print("IP Address: ");
64+
Serial.print("IP Address: ");
6065
Serial.println(ip);
6166
Serial.println(ip);
62-
67+
6368
// print your MAC address:
64-
byte mac[6];
69+
byte mac[6];
6570
WiFi.macAddress(mac);
6671
Serial.print("MAC address: ");
67-
Serial.print(mac[5],HEX);
72+
Serial.print(mac[5], HEX);
6873
Serial.print(":");
69-
Serial.print(mac[4],HEX);
74+
Serial.print(mac[4], HEX);
7075
Serial.print(":");
71-
Serial.print(mac[3],HEX);
76+
Serial.print(mac[3], HEX);
7277
Serial.print(":");
73-
Serial.print(mac[2],HEX);
78+
Serial.print(mac[2], HEX);
7479
Serial.print(":");
75-
Serial.print(mac[1],HEX);
80+
Serial.print(mac[1], HEX);
7681
Serial.print(":");
77-
Serial.println(mac[0],HEX);
78-
82+
Serial.println(mac[0], HEX);
83+
7984
// print your subnet mask:
8085
IPAddress subnet = WiFi.subnetMask();
8186
Serial.print("NetMask: ");
@@ -94,19 +99,19 @@ void printCurrentNet() {
9499

95100
// print the MAC address of the router you're attached to:
96101
byte bssid[6];
97-
WiFi.BSSID(bssid);
102+
WiFi.BSSID(bssid);
98103
Serial.print("BSSID: ");
99-
Serial.print(bssid[5],HEX);
104+
Serial.print(bssid[5], HEX);
100105
Serial.print(":");
101-
Serial.print(bssid[4],HEX);
106+
Serial.print(bssid[4], HEX);
102107
Serial.print(":");
103-
Serial.print(bssid[3],HEX);
108+
Serial.print(bssid[3], HEX);
104109
Serial.print(":");
105-
Serial.print(bssid[2],HEX);
110+
Serial.print(bssid[2], HEX);
106111
Serial.print(":");
107-
Serial.print(bssid[1],HEX);
112+
Serial.print(bssid[1], HEX);
108113
Serial.print(":");
109-
Serial.println(bssid[0],HEX);
114+
Serial.println(bssid[0], HEX);
110115

111116
// print the received signal strength:
112117
long rssi = WiFi.RSSI();
@@ -116,6 +121,6 @@ void printCurrentNet() {
116121
// print the encryption type:
117122
byte encryption = WiFi.encryptionType();
118123
Serial.print("Encryption Type:");
119-
Serial.println(encryption,HEX);
124+
Serial.println(encryption, HEX);
120125
}
121126

libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,55 @@
11
/*
2-
3-
This example connects to a WEP-encrypted Wifi network.
2+
3+
This example connects to a WEP-encrypted Wifi network.
44
Then it prints the MAC address of the Wifi shield,
55
the IP address obtained, and other network details.
6-
7-
If you use 40-bit WEP, you need a key that is 10 characters long,
8-
and the characters must be hexadecimal (0-9 or A-F).
9-
e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work
10-
(too short) and ABBAISDEAF won't work (I and S are not
11-
hexadecimal characters).
12-
13-
For 128-bit, you need a string that is 26 characters long.
14-
D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters,
6+
7+
If you use 40-bit WEP, you need a key that is 10 characters long,
8+
and the characters must be hexadecimal (0-9 or A-F).
9+
e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work
10+
(too short) and ABBAISDEAF won't work (I and S are not
11+
hexadecimal characters).
12+
13+
For 128-bit, you need a string that is 26 characters long.
14+
D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters,
1515
all in the 0-9, A-F range.
16-
16+
1717
Circuit:
1818
* WiFi shield attached
19-
19+
2020
created 13 July 2010
2121
by dlf (Metodo2 srl)
2222
modified 31 May 2012
2323
by Tom Igoe
2424
*/
25+
#include <SPI.h>
2526
#include <WiFi.h>
2627

27-
char ssid[] = "yourNetwork"; // your network SSID (name)
28+
char ssid[] = "yourNetwork"; // your network SSID (name)
2829
char key[] = "D0D0DEADF00DABBADEAFBEADED"; // your network key
2930
int keyIndex = 0; // your network key Index number
3031
int status = WL_IDLE_STATUS; // the Wifi radio's status
3132

3233
void setup() {
3334
//Initialize serial and wait for port to open:
34-
Serial.begin(9600);
35+
Serial.begin(9600);
3536
while (!Serial) {
3637
; // wait for serial port to connect. Needed for Leonardo only
3738
}
3839

3940
// check for the presence of the shield:
4041
if (WiFi.status() == WL_NO_SHIELD) {
41-
Serial.println("WiFi shield not present");
42+
Serial.println("WiFi shield not present");
4243
// don't continue:
43-
while(true);
44-
}
44+
while (true);
45+
}
46+
47+
String fv = WiFi.firmwareVersion();
48+
if ( fv != "1.1.0" )
49+
Serial.println("Please upgrade the firmware");
4550

4651
// attempt to connect to Wifi network:
47-
while ( status != WL_CONNECTED) {
52+
while ( status != WL_CONNECTED) {
4853
Serial.print("Attempting to connect to WEP network, SSID: ");
4954
Serial.println(ssid);
5055
status = WiFi.begin(ssid, keyIndex, key);
@@ -73,20 +78,20 @@ void printWifiData() {
7378
Serial.println(ip);
7479

7580
// print your MAC address:
76-
byte mac[6];
81+
byte mac[6];
7782
WiFi.macAddress(mac);
7883
Serial.print("MAC address: ");
79-
Serial.print(mac[5],HEX);
84+
Serial.print(mac[5], HEX);
8085
Serial.print(":");
81-
Serial.print(mac[4],HEX);
86+
Serial.print(mac[4], HEX);
8287
Serial.print(":");
83-
Serial.print(mac[3],HEX);
88+
Serial.print(mac[3], HEX);
8489
Serial.print(":");
85-
Serial.print(mac[2],HEX);
90+
Serial.print(mac[2], HEX);
8691
Serial.print(":");
87-
Serial.print(mac[1],HEX);
92+
Serial.print(mac[1], HEX);
8893
Serial.print(":");
89-
Serial.println(mac[0],HEX);
94+
Serial.println(mac[0], HEX);
9095
}
9196

9297
void printCurrentNet() {
@@ -96,19 +101,19 @@ void printCurrentNet() {
96101

97102
// print the MAC address of the router you're attached to:
98103
byte bssid[6];
99-
WiFi.BSSID(bssid);
104+
WiFi.BSSID(bssid);
100105
Serial.print("BSSID: ");
101-
Serial.print(bssid[5],HEX);
106+
Serial.print(bssid[5], HEX);
102107
Serial.print(":");
103-
Serial.print(bssid[4],HEX);
108+
Serial.print(bssid[4], HEX);
104109
Serial.print(":");
105-
Serial.print(bssid[3],HEX);
110+
Serial.print(bssid[3], HEX);
106111
Serial.print(":");
107-
Serial.print(bssid[2],HEX);
112+
Serial.print(bssid[2], HEX);
108113
Serial.print(":");
109-
Serial.print(bssid[1],HEX);
114+
Serial.print(bssid[1], HEX);
110115
Serial.print(":");
111-
Serial.println(bssid[0],HEX);
116+
Serial.println(bssid[0], HEX);
112117

113118
// print the received signal strength:
114119
long rssi = WiFi.RSSI();
@@ -118,7 +123,7 @@ void printCurrentNet() {
118123
// print the encryption type:
119124
byte encryption = WiFi.encryptionType();
120125
Serial.print("Encryption Type:");
121-
Serial.println(encryption,HEX);
126+
Serial.println(encryption, HEX);
122127
Serial.println();
123128
}
124129

0 commit comments

Comments
 (0)