mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
Changed examples to include shield detection
This commit is contained in:
parent
6e60b13013
commit
b2a8a47c58
@ -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>
|
||||||
|
|
||||||
@ -21,23 +21,28 @@ 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("WiFi shield not present");
|
||||||
|
// don't continue:
|
||||||
|
while(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// attempt to connect to Wifi network:
|
||||||
|
while ( status != WL_CONNECTED) {
|
||||||
|
Serial.print("Attempting to connect to open SSID: ");
|
||||||
Serial.println(ssid);
|
Serial.println(ssid);
|
||||||
status = WiFi.begin(ssid);
|
status = WiFi.begin(ssid);
|
||||||
|
|
||||||
// if you're not connected, stop here:
|
// wait 10 seconds for connection:
|
||||||
if ( status != WL_CONNECTED) {
|
delay(10000);
|
||||||
Serial.println("Couldn't get a wifi connection");
|
|
||||||
while(true);
|
|
||||||
}
|
}
|
||||||
// if you are connected :
|
|
||||||
else {
|
// you're connected now, so print out the data:
|
||||||
Serial.print("You're connected to the network");
|
Serial.print("You're connected to the network");
|
||||||
printCurrentNet();
|
printCurrentNet();
|
||||||
printWifiData();
|
printWifiData();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// check the network connection once every 10 seconds:
|
// check the network connection once every 10 seconds:
|
||||||
|
@ -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,23 +33,28 @@ 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("WiFi shield not present");
|
||||||
|
// don't continue:
|
||||||
|
while(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// attempt to connect to Wifi network:
|
||||||
|
while ( status != WL_CONNECTED) {
|
||||||
|
Serial.print("Attempting to connect to WEP network, SSID: ");
|
||||||
Serial.println(ssid);
|
Serial.println(ssid);
|
||||||
status = WiFi.begin(ssid, keyIndex, key);
|
status = WiFi.begin(ssid, keyIndex, key);
|
||||||
|
|
||||||
// if you're not connected, stop here:
|
// wait 10 seconds for connection:
|
||||||
if ( status != WL_CONNECTED) {
|
delay(10000);
|
||||||
Serial.println("Couldn't get a wifi connection");
|
|
||||||
while(true);
|
|
||||||
}
|
}
|
||||||
// if you are connected :
|
|
||||||
else {
|
// once you are connected :
|
||||||
Serial.print("You're connected to the network");
|
Serial.print("You're connected to the network");
|
||||||
printCurrentNet();
|
printCurrentNet();
|
||||||
printWifiData();
|
printWifiData();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// check the network connection once every 10 seconds:
|
// check the network connection once every 10 seconds:
|
||||||
@ -115,3 +120,4 @@ void printCurrentNet() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -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:
|
// check for the presence of the shield:
|
||||||
Serial.print("Attempting to connect to WPA network: ");
|
if (WiFi.status() == WL_NO_SHIELD) {
|
||||||
Serial.println(ssid);
|
Serial.println("WiFi shield not present");
|
||||||
status = WiFi.begin(ssid, pass);
|
// 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:
|
||||||
|
while ( status != WL_CONNECTED) {
|
||||||
|
Serial.print("Attempting to connect to WPA SSID: ");
|
||||||
|
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");
|
Serial.print("You're connected to the network");
|
||||||
printCurrentNet();
|
printCurrentNet();
|
||||||
printWifiData();
|
printWifiData();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -22,8 +22,14 @@ 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:
|
||||||
|
@ -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)
|
||||||
|
|
||||||
@ -37,15 +37,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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
@ -54,15 +54,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);
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
|
||||||
@ -52,15 +53,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);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
@ -42,15 +42,20 @@ 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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user