mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Updated all Wifi web client and server examples to attempt continual reconnects to the SSID
This commit is contained in:
parent
e8118e2270
commit
78b5e3cba5
@ -21,7 +21,6 @@
|
||||
void setup() {
|
||||
// initialize serial and wait for the port to open:
|
||||
Serial.begin(9600);
|
||||
while(!Serial) ;
|
||||
|
||||
// attempt to connect using WEP encryption:
|
||||
Serial.println("Initializing Wifi...");
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
created 18 Dec 2009
|
||||
by David A. Mellis
|
||||
modified 12 Mar 2012
|
||||
modified 23 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
@ -34,28 +34,32 @@ WiFiServer server(23);
|
||||
boolean alreadyConnected = false; // whether or not the client was connected previously
|
||||
|
||||
void setup() {
|
||||
// initialize serial:
|
||||
// start serial port:
|
||||
Serial.begin(9600);
|
||||
Serial.println("Attempting to connect to Wifi network...");
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(ssid);
|
||||
|
||||
status = WiFi.begin(ssid, pass);
|
||||
if ( status != WL_CONNECTED) {
|
||||
Serial.println("Couldn't get a wifi connection");
|
||||
while(true);
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
status = WiFi.begin(ssid, pass);
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
else {
|
||||
server.begin();
|
||||
Serial.print("Connected to wifi.");
|
||||
printWifiStatus();
|
||||
}
|
||||
// start the server:
|
||||
server.begin();
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
// print the Wifi board/shield's IP address:
|
||||
Serial.print("My IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// wait for a new client:
|
||||
WiFiClient client = server.available();
|
||||
|
||||
|
||||
|
||||
// when the client sends the first byte, say hello:
|
||||
if (client) {
|
||||
if (!alreadyConnected) {
|
||||
@ -95,3 +99,4 @@ void printWifiStatus() {
|
||||
Serial.println(" dBm");
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,7 +15,8 @@
|
||||
* Analog sensor attached to analog in 0
|
||||
* Wifi shield attached to pins 10, 11, 12, 13
|
||||
|
||||
created 13 March 2012
|
||||
created 13 Mar 2012
|
||||
modified 23 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
This code is in the public domain.
|
||||
@ -45,21 +46,22 @@ boolean lastConnected = false; // state of the connection last t
|
||||
const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
|
||||
|
||||
void setup() {
|
||||
// start serial port:
|
||||
Serial.begin(9600);
|
||||
Serial.println("Attempting to connect to Wifi network...");
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(ssid);
|
||||
|
||||
status = WiFi.begin(ssid, pass);
|
||||
if ( status != WL_CONNECTED) {
|
||||
Serial.println("Couldn't get a wifi connection");
|
||||
// stop here and do nothing:
|
||||
while(true);
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
status = WiFi.begin(ssid, pass);
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
else {
|
||||
Serial.println("Connected to wifi");
|
||||
printWifiStatus();
|
||||
}
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
// print the Wifi board/shield's IP address:
|
||||
Serial.print("My IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,7 +18,8 @@
|
||||
* Analog sensor attached to analog in 0
|
||||
* Wifi shield attached to pins 10, 11, 12, 13
|
||||
|
||||
created 16 March 2012
|
||||
created 16 Mar 2012
|
||||
modified 23 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
This code is in the public domain.
|
||||
@ -50,21 +51,22 @@ boolean lastConnected = false; // state of the connection last t
|
||||
const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
|
||||
|
||||
void setup() {
|
||||
// start serial port:
|
||||
Serial.begin(9600);
|
||||
Serial.println("Attempting to connect to Wifi network...");
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(ssid);
|
||||
|
||||
status = WiFi.begin(ssid, pass);
|
||||
if ( status != WL_CONNECTED) {
|
||||
Serial.println("Couldn't get a wifi connection");
|
||||
// stop here and do nothing:
|
||||
while(true);
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
status = WiFi.begin(ssid, pass);
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
else {
|
||||
Serial.println("Connected to wifi");
|
||||
printWifiStatus();
|
||||
}
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
// print the Wifi board/shield's IP address:
|
||||
Serial.print("My IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -161,3 +163,4 @@ void printWifiStatus() {
|
||||
Serial.println(" dBm");
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
Circuit:
|
||||
* WiFi shield attached to pins 10, 11, 12, 13
|
||||
|
||||
created 15 Mar 2012
|
||||
created 23 apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
This code is in the public domain.
|
||||
@ -24,8 +24,8 @@
|
||||
|
||||
char ssid[] = "YourNetwork"; // your network SSID (name)
|
||||
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 status = WL_IDLE_STATUS; // status of the wifi connection
|
||||
|
||||
// initialize the library instance:
|
||||
@ -49,22 +49,25 @@ void setup() {
|
||||
// reserve space for the strings:
|
||||
currentLine.reserve(256);
|
||||
tweet.reserve(150);
|
||||
// initialize serial:
|
||||
// start serial port:
|
||||
Serial.begin(9600);
|
||||
Serial.println("Attempting to connect to WPA network...");
|
||||
|
||||
status = WiFi.begin(ssid, pass);
|
||||
if ( status != WL_CONNECTED) {
|
||||
Serial.println("Couldn't get a wifi connection");
|
||||
// stop here and do nothing:
|
||||
while(true);
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
status = WiFi.begin(ssid, pass);
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
else {
|
||||
Serial.println("Connected to wifi");
|
||||
printWifiStatus();
|
||||
connectToServer();
|
||||
}
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
// print the Wifi board/shield's IP address:
|
||||
Serial.print("My IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
connectToServer();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (client.connected()) {
|
||||
@ -147,3 +150,4 @@ void printWifiStatus() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -5,9 +5,9 @@
|
||||
This sketch connects to a website (http://www.google.com)
|
||||
using a WiFi shield.
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the Wifi.begin() call accordingly.
|
||||
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the Wifi.begin() call accordingly.
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 13 Mar 2012
|
||||
modified 23 Apr 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
|
||||
@ -41,38 +41,37 @@ WiFiClient client;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("Attempting to connect to Wifi network...");
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(ssid);
|
||||
|
||||
status = WiFi.begin(ssid, pass);
|
||||
if ( status != WL_CONNECTED) {
|
||||
Serial.println("Couldn't get a wifi connection");
|
||||
// stop here and do nothing:
|
||||
while(true);
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
status = WiFi.begin(ssid, pass);
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
else {
|
||||
Serial.println("Connected to wifi");
|
||||
printWifiStatus();
|
||||
Serial.println("\nStarting connection to server...");
|
||||
// if you get a connection, report back via serial:
|
||||
if (client.connect(server, 80)) {
|
||||
Serial.println("connected to server");
|
||||
// Make a HTTP request:
|
||||
client.println("GET /search?q=arduino HTTP/1.1");
|
||||
client.println("Host:www.google.com");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
}
|
||||
Serial.println("Connected to wifi");
|
||||
printWifiStatus();
|
||||
|
||||
Serial.println("\nStarting connection to server...");
|
||||
// if you get a connection, report back via serial:
|
||||
if (client.connect(server, 80)) {
|
||||
Serial.println("connected to server");
|
||||
// Make a HTTP request:
|
||||
client.println("GET /search?q=arduino HTTP/1.1");
|
||||
client.println("Host:www.google.com");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// if there are incoming bytes available
|
||||
// from the server, read them and print them:
|
||||
if (client.available()>0) {
|
||||
while (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.print(c);
|
||||
Serial.write(c);
|
||||
}
|
||||
|
||||
// if the server's disconnected, stop the client:
|
||||
@ -94,7 +93,7 @@ void printWifiStatus() {
|
||||
|
||||
// print your WiFi shield's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
// print the received signal strength:
|
||||
@ -107,3 +106,4 @@ void printWifiStatus() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -13,11 +13,9 @@
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 20 Mar 2012
|
||||
modified 23 Apr 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
@ -31,22 +29,23 @@ int status = WL_IDLE_STATUS;
|
||||
WiFiServer server(80);
|
||||
|
||||
void setup() {
|
||||
// initialize serial:
|
||||
// start serial port:
|
||||
Serial.begin(9600);
|
||||
Serial.println("Attempting to connect to Wifi network...");
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(ssid);
|
||||
|
||||
status = WiFi.begin(ssid, pass);
|
||||
if ( status != WL_CONNECTED) {
|
||||
Serial.println("Couldn't get a wifi connection");
|
||||
while(true);
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
status = WiFi.begin(ssid, pass);
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
else {
|
||||
server.begin();
|
||||
Serial.print("Connected to wifi.");
|
||||
printWifiStatus();
|
||||
}
|
||||
server.begin();
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
// print the Wifi board/shield's IP address:
|
||||
Serial.print("My IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user