1919
2020 created 13 July 2010
2121 by dlf (Metodo2 srl)
22- modified 4 Mar 2012
22+ modified 31 May 2012
2323 by Tom Igoe
2424 */
2525#include < WiFi.h>
@@ -33,22 +33,27 @@ void setup() {
3333 // initialize serial:
3434 Serial.begin (9600 );
3535
36- // attempt to connect to an open network:
37- Serial.print (" Attempting to connect to WEP network: " );
38- Serial.println (ssid);
39- status = WiFi.begin (ssid, keyIndex, key);
40-
41- // if you're not connected, stop here:
42- if ( status != WL_CONNECTED) {
43- Serial.println (" Couldn't get a wifi connection" );
36+ // check for the presence of the shield:
37+ if (WiFi.status () == WL_NO_SHIELD) {
38+ Serial.println (" WiFi shield not present" );
39+ // don't continue:
4440 while (true );
4541 }
46- // if you are connected :
47- else {
48- Serial.print (" You're connected to the network" );
49- printCurrentNet ();
50- printWifiData ();
42+
43+ // attempt to connect to Wifi network:
44+ while ( status != WL_CONNECTED) {
45+ Serial.print (" Attempting to connect to WEP network, SSID: " );
46+ Serial.println (ssid);
47+ status = WiFi.begin (ssid, keyIndex, key);
48+
49+ // wait 10 seconds for connection:
50+ delay (10000 );
5151 }
52+
53+ // once you are connected :
54+ Serial.print (" You're connected to the network" );
55+ printCurrentNet ();
56+ printWifiData ();
5257}
5358
5459void loop () {
@@ -60,7 +65,7 @@ void loop() {
6065void printWifiData () {
6166 // print your WiFi shield's IP address:
6267 IPAddress ip = WiFi.localIP ();
63- Serial.print (" IP Address: " );
68+ Serial.print (" IP Address: " );
6469 Serial.println (ip);
6570 Serial.println (ip);
6671
@@ -115,3 +120,4 @@ void printCurrentNet() {
115120}
116121
117122
123+
0 commit comments