mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-20 21:01:25 +03:00
Updated all Wifi web client and server examples to attempt continual reconnects to the SSID
This commit is contained in:
@ -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() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user