1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-03-14 11:29:26 +01:00

Changed examples to include shield detection

This commit is contained in:
Tom Igoe 2012-05-31 12:16:14 -04:00
parent 6e60b13013
commit b2a8a47c58
11 changed files with 157 additions and 92 deletions

View File

@ -9,8 +9,8 @@
created 13 July 2010 created 13 July 2010
by dlf (Metodo2 srl) by dlf (Metodo2 srl)
modified 29 Feb 2012 modified 31 May 2012
by Scott Fitzgerald by Tom Igoe
*/ */
#include <WiFi.h> #include <WiFi.h>
@ -20,23 +20,28 @@ int status = WL_IDLE_STATUS; // the Wifi radio's status
void setup() { void setup() {
// initialize serial: // initialize serial:
Serial.begin(9600); Serial.begin(9600);
// attempt to connect to an open network: // check for the presence of the shield:
Serial.print("Attempting to connect to open network: "); if (WiFi.status() == WL_NO_SHIELD) {
Serial.println(ssid); Serial.println("WiFi shield not present");
status = WiFi.begin(ssid); // don't continue:
// if you're not connected, stop here:
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true); while(true);
} }
// if you are connected :
else { // attempt to connect to Wifi network:
Serial.print("You're connected to the network"); while ( status != WL_CONNECTED) {
printCurrentNet(); Serial.print("Attempting to connect to open SSID: ");
printWifiData(); Serial.println(ssid);
status = WiFi.begin(ssid);
// wait 10 seconds for connection:
delay(10000);
} }
// you're connected now, so print out the data:
Serial.print("You're connected to the network");
printCurrentNet();
printWifiData();
} }
void loop() { void loop() {

View File

@ -19,7 +19,7 @@
created 13 July 2010 created 13 July 2010
by dlf (Metodo2 srl) by dlf (Metodo2 srl)
modified 4 Mar 2012 modified 31 May 2012
by Tom Igoe by Tom Igoe
*/ */
#include <WiFi.h> #include <WiFi.h>
@ -33,22 +33,27 @@ void setup() {
// initialize serial: // initialize serial:
Serial.begin(9600); Serial.begin(9600);
// attempt to connect to an open network: // check for the presence of the shield:
Serial.print("Attempting to connect to WEP network: "); if (WiFi.status() == WL_NO_SHIELD) {
Serial.println(ssid); Serial.println("WiFi shield not present");
status = WiFi.begin(ssid, keyIndex, key); // don't continue:
// if you're not connected, stop here:
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true); while(true);
} }
// if you are connected :
else { // attempt to connect to Wifi network:
Serial.print("You're connected to the network"); while ( status != WL_CONNECTED) {
printCurrentNet(); Serial.print("Attempting to connect to WEP network, SSID: ");
printWifiData(); Serial.println(ssid);
status = WiFi.begin(ssid, keyIndex, key);
// wait 10 seconds for connection:
delay(10000);
} }
// once you are connected :
Serial.print("You're connected to the network");
printCurrentNet();
printWifiData();
} }
void loop() { void loop() {
@ -60,7 +65,7 @@ void loop() {
void printWifiData() { void printWifiData() {
// print your WiFi shield's IP address: // print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP(); IPAddress ip = WiFi.localIP();
Serial.print("IP Address: "); Serial.print("IP Address: ");
Serial.println(ip); Serial.println(ip);
Serial.println(ip); Serial.println(ip);
@ -115,3 +120,4 @@ void printCurrentNet() {
} }

View File

@ -9,35 +9,42 @@
created 13 July 2010 created 13 July 2010
by dlf (Metodo2 srl) by dlf (Metodo2 srl)
modified 29 Feb 2012 modified 31 May 2012
by Scott Fitzgerald by Tom Igoe
*/ */
#include <WiFi.h> #include <WiFi.h>
char ssid[] = "networkName"; // your network SSID (name) char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "yourPassword"; // your network password char pass[] = "secretPassword"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status int status = WL_IDLE_STATUS; // the Wifi radio's status
void setup() { void setup() {
// initialize serial: // initialize serial:
Serial.begin(9600); Serial.begin(9600);
// attempt to connect to an open network:
Serial.print("Attempting to connect to WPA network: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
// if you're not connected, stop here: // check for the presence of the shield:
if ( status != WL_CONNECTED) { if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("Couldn't get a wifi connection"); Serial.println("WiFi shield not present");
// don't continue:
while(true); while(true);
} }
// if you are connected :
else { // attempt to connect to Wifi network:
Serial.print("You're connected to the network"); while ( status != WL_CONNECTED) {
printCurrentNet(); Serial.print("Attempting to connect to WPA SSID: ");
printWifiData(); Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
} }
// you're connected now, so print out the data:
Serial.print("You're connected to the network");
printCurrentNet();
printWifiData();
} }
void loop() { void loop() {

View File

@ -10,7 +10,7 @@
created 13 July 2010 created 13 July 2010
by dlf (Metodo2 srl) by dlf (Metodo2 srl)
modified 22 April 2012 modified 31 May 2012
by Tom Igoe by Tom Igoe
*/ */
@ -21,9 +21,15 @@
void setup() { void setup() {
// initialize serial and wait for the port to open: // initialize serial and wait for the port to open:
Serial.begin(9600); Serial.begin(9600);
// attempt to connect using WEP encryption: // check for the presence of the shield:
Serial.println("Initializing Wifi..."); if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
// Print WiFi MAC address:
printMacAddress(); printMacAddress();
// scan for existing networks: // scan for existing networks:

View File

@ -14,7 +14,7 @@
created 18 Dec 2009 created 18 Dec 2009
by David A. Mellis by David A. Mellis
modified 23 Apr 2012 modified 31 May 2012
by Tom Igoe by Tom Igoe
*/ */
@ -22,8 +22,8 @@
#include <SPI.h> #include <SPI.h>
#include <WiFi.h> #include <WiFi.h>
char ssid[] = "YourNetwork"; // your network SSID (name) char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP) char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP) int keyIndex = 0; // your network key Index number (needed only for WEP)
@ -36,16 +36,21 @@ boolean alreadyConnected = false; // whether or not the client was connected pre
void setup() { void setup() {
// start serial port: // start serial port:
Serial.begin(9600); Serial.begin(9600);
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
// attempt to connect to Wifi network: // attempt to connect to Wifi network:
while ( status != WL_CONNECTED) { while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: "); Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid); Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass); status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true);
}
// wait 10 seconds for connection: // wait 10 seconds for connection:
delay(10000); delay(10000);
} }

View File

@ -16,7 +16,7 @@
* Wifi shield attached to pins 10, 11, 12, 13 * Wifi shield attached to pins 10, 11, 12, 13
created 13 Mar 2012 created 13 Mar 2012
modified 14 May 2012 modified 31 May 2012
by Tom Igoe by Tom Igoe
This code is in the public domain. This code is in the public domain.
@ -49,15 +49,20 @@ void setup() {
// start serial port: // start serial port:
Serial.begin(9600); Serial.begin(9600);
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
// attempt to connect to Wifi network: // attempt to connect to Wifi network:
while ( status != WL_CONNECTED) { while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: "); Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid); Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass); status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true);
}
// wait 10 seconds for connection: // wait 10 seconds for connection:
delay(10000); delay(10000);
} }

View File

@ -19,7 +19,7 @@
* Wifi shield attached to pins 10, 11, 12, 13 * Wifi shield attached to pins 10, 11, 12, 13
created 16 Mar 2012 created 16 Mar 2012
modified 14 May 2012 modified 31 May 2012
by Tom Igoe by Tom Igoe
This code is in the public domain. This code is in the public domain.
@ -53,16 +53,21 @@ const unsigned long postingInterval = 10*1000; //delay between updates to cosm.
void setup() { void setup() {
// start serial port: // start serial port:
Serial.begin(9600); Serial.begin(9600);
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
// attempt to connect to Wifi network: // attempt to connect to Wifi network:
while ( status != WL_CONNECTED) { while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: "); Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid); Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass); status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true);
}
// wait 10 seconds for connection: // wait 10 seconds for connection:
delay(10000); delay(10000);
} }

View File

@ -14,6 +14,7 @@
* WiFi shield attached to pins 10, 11, 12, 13 * WiFi shield attached to pins 10, 11, 12, 13
created 23 apr 2012 created 23 apr 2012
modified 31 May 2012
by Tom Igoe by Tom Igoe
This code is in the public domain. This code is in the public domain.
@ -22,7 +23,7 @@
#include <SPI.h> #include <SPI.h>
#include <WiFi.h> #include <WiFi.h>
char ssid[] = "YourNetwork"; // your network SSID (name) char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP) char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP) int keyIndex = 0; // your network key Index number (needed only for WEP)
@ -51,16 +52,21 @@ void setup() {
tweet.reserve(150); tweet.reserve(150);
// start serial port: // start serial port:
Serial.begin(9600); Serial.begin(9600);
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
// attempt to connect to Wifi network: // attempt to connect to Wifi network:
while ( status != WL_CONNECTED) { while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: "); Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid); Serial.println(ssid);
status = WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
if ( status != WL_CONNECTED) { status = WiFi.begin(ssid, pass);
Serial.println("Couldn't get a wifi connection");
while(true);
}
// wait 10 seconds for connection: // wait 10 seconds for connection:
delay(10000); delay(10000);
} }

View File

@ -16,7 +16,7 @@
created 13 July 2010 created 13 July 2010
by dlf (Metodo2 srl) by dlf (Metodo2 srl)
modified 23 Apr 2012 modified 31 May 2012
by Tom Igoe by Tom Igoe
*/ */
@ -24,8 +24,8 @@
#include <SPI.h> #include <SPI.h>
#include <WiFi.h> #include <WiFi.h>
char ssid[] = "YourNetwork"; // your network SSID (name) char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP) char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP) int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS; int status = WL_IDLE_STATUS;
@ -41,16 +41,21 @@ WiFiClient client;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
// attempt to connect to Wifi network: // attempt to connect to Wifi network:
while ( status != WL_CONNECTED) { while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: "); Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid); Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass); status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true);
}
// wait 10 seconds for connection: // wait 10 seconds for connection:
delay(10000); delay(10000);
} }

View File

@ -7,7 +7,8 @@
Circuit: Circuit:
* Wifi shield attached to pins 10, 11, 12, 13 * Wifi shield attached to pins 10, 11, 12, 13
created 23 Apr 2012 created 23 April 2012
modifide 31 May 2012
by Tom Igoe by Tom Igoe
http://arduino.cc/en/Tutorial/WifiWebClientRepeating http://arduino.cc/en/Tutorial/WifiWebClientRepeating
@ -38,15 +39,20 @@ void setup() {
// start serial port: // start serial port:
Serial.begin(9600); Serial.begin(9600);
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
// attempt to connect to Wifi network: // attempt to connect to Wifi network:
while ( status != WL_CONNECTED) { while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: "); Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid); Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass); status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true);
}
// wait 10 seconds for connection: // wait 10 seconds for connection:
delay(10000); delay(10000);
} }

View File

@ -13,7 +13,7 @@
created 13 July 2010 created 13 July 2010
by dlf (Metodo2 srl) by dlf (Metodo2 srl)
modified 23 Apr 2012 modified 31 May 2012
by Tom Igoe by Tom Igoe
*/ */
#include <SPI.h> #include <SPI.h>
@ -32,11 +32,20 @@ void setup() {
// start serial port: // start serial port:
Serial.begin(9600); Serial.begin(9600);
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
// attempt to connect to Wifi network: // attempt to connect to Wifi network:
while ( status != WL_CONNECTED) { while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: "); Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid); Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass); status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection: // wait 10 seconds for connection:
delay(10000); delay(10000);
} }