mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-19 09:42:11 +03:00
Updated all Wifi web client and server examples to attempt continual reconnects to the SSID
This commit is contained in:
@ -21,7 +21,6 @@
|
|||||||
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);
|
||||||
while(!Serial) ;
|
|
||||||
|
|
||||||
// attempt to connect using WEP encryption:
|
// attempt to connect using WEP encryption:
|
||||||
Serial.println("Initializing Wifi...");
|
Serial.println("Initializing Wifi...");
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
created 18 Dec 2009
|
created 18 Dec 2009
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 12 Mar 2012
|
modified 23 Apr 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@ -34,23 +34,27 @@ WiFiServer server(23);
|
|||||||
boolean alreadyConnected = false; // whether or not the client was connected previously
|
boolean alreadyConnected = false; // whether or not the client was connected previously
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// initialize serial:
|
// start serial port:
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.println("Attempting to connect to Wifi network...");
|
|
||||||
Serial.print("SSID: ");
|
|
||||||
Serial.println(ssid);
|
|
||||||
|
|
||||||
|
// 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);
|
status = WiFi.begin(ssid, pass);
|
||||||
if ( status != WL_CONNECTED) {
|
// wait 10 seconds for connection:
|
||||||
Serial.println("Couldn't get a wifi connection");
|
delay(10000);
|
||||||
while(true);
|
|
||||||
}
|
}
|
||||||
else {
|
// start the server:
|
||||||
server.begin();
|
server.begin();
|
||||||
Serial.print("Connected to wifi.");
|
// you're connected now, so print out the status:
|
||||||
printWifiStatus();
|
printWifiStatus();
|
||||||
}
|
// print the Wifi board/shield's IP address:
|
||||||
|
Serial.print("My IP address: ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// wait for a new client:
|
// wait for a new client:
|
||||||
WiFiClient client = server.available();
|
WiFiClient client = server.available();
|
||||||
@ -95,3 +99,4 @@ void printWifiStatus() {
|
|||||||
Serial.println(" dBm");
|
Serial.println(" dBm");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,8 @@
|
|||||||
* Analog sensor attached to analog in 0
|
* Analog sensor attached to analog in 0
|
||||||
* Wifi shield attached to pins 10, 11, 12, 13
|
* Wifi shield attached to pins 10, 11, 12, 13
|
||||||
|
|
||||||
created 13 March 2012
|
created 13 Mar 2012
|
||||||
|
modified 23 Apr 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
This code is in the public domain.
|
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
|
const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
// start serial port:
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.println("Attempting to connect to Wifi network...");
|
|
||||||
Serial.print("SSID: ");
|
|
||||||
Serial.println(ssid);
|
|
||||||
|
|
||||||
|
// 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);
|
status = WiFi.begin(ssid, pass);
|
||||||
if ( status != WL_CONNECTED) {
|
// wait 10 seconds for connection:
|
||||||
Serial.println("Couldn't get a wifi connection");
|
delay(10000);
|
||||||
// stop here and do nothing:
|
|
||||||
while(true);
|
|
||||||
}
|
}
|
||||||
else {
|
// you're connected now, so print out the status:
|
||||||
Serial.println("Connected to wifi");
|
|
||||||
printWifiStatus();
|
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
|
* Analog sensor attached to analog in 0
|
||||||
* Wifi shield attached to pins 10, 11, 12, 13
|
* Wifi shield attached to pins 10, 11, 12, 13
|
||||||
|
|
||||||
created 16 March 2012
|
created 16 Mar 2012
|
||||||
|
modified 23 Apr 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
This code is in the public domain.
|
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
|
const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
// start serial port:
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.println("Attempting to connect to Wifi network...");
|
|
||||||
Serial.print("SSID: ");
|
|
||||||
Serial.println(ssid);
|
|
||||||
|
|
||||||
|
// 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);
|
status = WiFi.begin(ssid, pass);
|
||||||
if ( status != WL_CONNECTED) {
|
// wait 10 seconds for connection:
|
||||||
Serial.println("Couldn't get a wifi connection");
|
delay(10000);
|
||||||
// stop here and do nothing:
|
|
||||||
while(true);
|
|
||||||
}
|
}
|
||||||
else {
|
// you're connected now, so print out the status:
|
||||||
Serial.println("Connected to wifi");
|
|
||||||
printWifiStatus();
|
printWifiStatus();
|
||||||
}
|
// print the Wifi board/shield's IP address:
|
||||||
|
Serial.print("My IP address: ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@ -161,3 +163,4 @@ void printWifiStatus() {
|
|||||||
Serial.println(" dBm");
|
Serial.println(" dBm");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
Circuit:
|
Circuit:
|
||||||
* WiFi shield attached to pins 10, 11, 12, 13
|
* WiFi shield attached to pins 10, 11, 12, 13
|
||||||
|
|
||||||
created 15 Mar 2012
|
created 23 apr 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
This code is in the public domain.
|
This code is in the public domain.
|
||||||
@ -24,8 +24,8 @@
|
|||||||
|
|
||||||
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)
|
||||||
|
|
||||||
int status = WL_IDLE_STATUS; // status of the wifi connection
|
int status = WL_IDLE_STATUS; // status of the wifi connection
|
||||||
|
|
||||||
// initialize the library instance:
|
// initialize the library instance:
|
||||||
@ -49,22 +49,25 @@ void setup() {
|
|||||||
// reserve space for the strings:
|
// reserve space for the strings:
|
||||||
currentLine.reserve(256);
|
currentLine.reserve(256);
|
||||||
tweet.reserve(150);
|
tweet.reserve(150);
|
||||||
// initialize serial:
|
// start serial port:
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.println("Attempting to connect to WPA network...");
|
|
||||||
|
|
||||||
|
// 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);
|
status = WiFi.begin(ssid, pass);
|
||||||
if ( status != WL_CONNECTED) {
|
// wait 10 seconds for connection:
|
||||||
Serial.println("Couldn't get a wifi connection");
|
delay(10000);
|
||||||
// stop here and do nothing:
|
|
||||||
while(true);
|
|
||||||
}
|
}
|
||||||
else {
|
// you're connected now, so print out the status:
|
||||||
Serial.println("Connected to wifi");
|
|
||||||
printWifiStatus();
|
printWifiStatus();
|
||||||
|
// print the Wifi board/shield's IP address:
|
||||||
|
Serial.print("My IP address: ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
connectToServer();
|
connectToServer();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
if (client.connected()) {
|
if (client.connected()) {
|
||||||
@ -147,3 +150,4 @@ void printWifiStatus() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
created 13 July 2010
|
created 13 July 2010
|
||||||
by dlf (Metodo2 srl)
|
by dlf (Metodo2 srl)
|
||||||
modified 13 Mar 2012
|
modified 23 Apr 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -41,19 +41,18 @@ WiFiClient client;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.println("Attempting to connect to Wifi network...");
|
|
||||||
Serial.print("SSID: ");
|
|
||||||
Serial.println(ssid);
|
|
||||||
|
|
||||||
|
// 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);
|
status = WiFi.begin(ssid, pass);
|
||||||
if ( status != WL_CONNECTED) {
|
// wait 10 seconds for connection:
|
||||||
Serial.println("Couldn't get a wifi connection");
|
delay(10000);
|
||||||
// stop here and do nothing:
|
|
||||||
while(true);
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
Serial.println("Connected to wifi");
|
Serial.println("Connected to wifi");
|
||||||
printWifiStatus();
|
printWifiStatus();
|
||||||
|
|
||||||
Serial.println("\nStarting connection to server...");
|
Serial.println("\nStarting connection to server...");
|
||||||
// if you get a connection, report back via serial:
|
// if you get a connection, report back via serial:
|
||||||
if (client.connect(server, 80)) {
|
if (client.connect(server, 80)) {
|
||||||
@ -63,16 +62,16 @@ void setup() {
|
|||||||
client.println("Host:www.google.com");
|
client.println("Host:www.google.com");
|
||||||
client.println("Connection: close");
|
client.println("Connection: close");
|
||||||
client.println();
|
client.println();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// if there are incoming bytes available
|
// if there are incoming bytes available
|
||||||
// from the server, read them and print them:
|
// from the server, read them and print them:
|
||||||
if (client.available()>0) {
|
while (client.available()) {
|
||||||
char c = client.read();
|
char c = client.read();
|
||||||
Serial.print(c);
|
Serial.write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the server's disconnected, stop the client:
|
// if the server's disconnected, stop the client:
|
||||||
@ -107,3 +106,4 @@ void printWifiStatus() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,11 +13,9 @@
|
|||||||
|
|
||||||
created 13 July 2010
|
created 13 July 2010
|
||||||
by dlf (Metodo2 srl)
|
by dlf (Metodo2 srl)
|
||||||
modified 20 Mar 2012
|
modified 23 Apr 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
|
||||||
@ -31,22 +29,23 @@ int status = WL_IDLE_STATUS;
|
|||||||
WiFiServer server(80);
|
WiFiServer server(80);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// initialize serial:
|
// start serial port:
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.println("Attempting to connect to Wifi network...");
|
|
||||||
Serial.print("SSID: ");
|
|
||||||
Serial.println(ssid);
|
|
||||||
|
|
||||||
|
// 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);
|
status = WiFi.begin(ssid, pass);
|
||||||
if ( status != WL_CONNECTED) {
|
// wait 10 seconds for connection:
|
||||||
Serial.println("Couldn't get a wifi connection");
|
delay(10000);
|
||||||
while(true);
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
server.begin();
|
server.begin();
|
||||||
Serial.print("Connected to wifi.");
|
// you're connected now, so print out the status:
|
||||||
printWifiStatus();
|
printWifiStatus();
|
||||||
}
|
// print the Wifi board/shield's IP address:
|
||||||
|
Serial.print("My IP address: ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user