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

Updated WifiWebServer to give more diagnostic info

This commit is contained in:
Tom Igoe 2012-03-20 10:36:33 -04:00
parent 533edc6387
commit bcfde7af9a

View File

@ -13,7 +13,7 @@
created 13 July 2010 created 13 July 2010
by dlf (Metodo2 srl) by dlf (Metodo2 srl)
modified 4 Mar 2012 modified 20 Mar 2012
by Tom Igoe by Tom Igoe
*/ */
@ -21,9 +21,10 @@
#include <SPI.h> #include <SPI.h>
#include <WiFi.h> #include <WiFi.h>
char ssid[] = "YourNetwork"; // your network SSID (name)
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP) char ssid[] = "yourNetwork"; // your network SSID (name)
int keyIndex = 0; // your network key Index number (needed only for WEP) char pass[] = "secretPassword"; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS; int status = WL_IDLE_STATUS;
@ -53,11 +54,13 @@ void loop() {
// listen for incoming clients // listen for incoming clients
WiFiClient client = server.available(); WiFiClient client = server.available();
if (client) { if (client) {
Serial.println("new client");
// an http request ends with a blank line // an http request ends with a blank line
boolean currentLineIsBlank = true; boolean currentLineIsBlank = true;
while (client.connected()) { while (client.connected()) {
if (client.available()) { if (client.available()) {
char c = client.read(); char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline // if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended, // character) and the line is blank, the http request has ended,
// so you can send a reply // so you can send a reply
@ -65,18 +68,23 @@ void loop() {
// send a standard http response header // send a standard http response header
client.println("HTTP/1.1 200 OK"); client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html"); client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println(); client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>"); client.println("<html>");
// add a meta refresh tag, so the browser pulls again every 5 seconds:
client.println("<meta http-equiv=\"refresh\" content=\"5\">");
// output the value of each analog input pin // output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) { for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input "); client.print("analog input ");
client.print(analogChannel); client.print(analogChannel);
client.print(" is "); client.print(" is ");
client.print(analogRead(analogChannel)); client.print(sensorReading);
client.println("<br />"); client.println("<br />");
} }
client.println("</html>"); client.println("</html>");
break; break;
} }
if (c == '\n') { if (c == '\n') {
// you're starting a new line // you're starting a new line
@ -90,8 +98,9 @@ void loop() {
} }
// give the web browser time to receive the data // give the web browser time to receive the data
delay(1); delay(1);
// close the connection: // close the connection:
client.stop(); client.stop();
Serial.println("client disonnected");
} }
} }
@ -103,7 +112,7 @@ void printWifiStatus() {
// 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);
// print the received signal strength: // print the received signal strength:
@ -112,3 +121,4 @@ void printWifiStatus() {
Serial.print(rssi); Serial.print(rssi);
Serial.println(" dBm"); Serial.println(" dBm");
} }