Skip to content

Commit bcfde7a

Browse files
author
Tom Igoe
committed
Updated WifiWebServer to give more diagnostic info
1 parent 533edc6 commit bcfde7a

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

WiFi/examples/WifiWebServer/WifiWebServer.ino

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@
1313
1414
created 13 July 2010
1515
by dlf (Metodo2 srl)
16-
modified 4 Mar 2012
16+
modified 20 Mar 2012
1717
by Tom Igoe
1818
*/
1919

2020

2121
#include <SPI.h>
2222
#include <WiFi.h>
2323

24-
char ssid[] = "YourNetwork"; // your network SSID (name)
25-
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
26-
int keyIndex = 0; // your network key Index number (needed only for WEP)
24+
25+
char ssid[] = "yourNetwork"; // your network SSID (name)
26+
char pass[] = "secretPassword"; // your network password
27+
int keyIndex = 0; // your network key Index number (needed only for WEP)
2728

2829
int status = WL_IDLE_STATUS;
2930

@@ -53,30 +54,37 @@ void loop() {
5354
// listen for incoming clients
5455
WiFiClient client = server.available();
5556
if (client) {
57+
Serial.println("new client");
5658
// an http request ends with a blank line
5759
boolean currentLineIsBlank = true;
5860
while (client.connected()) {
5961
if (client.available()) {
6062
char c = client.read();
63+
Serial.write(c);
6164
// if you've gotten to the end of the line (received a newline
6265
// character) and the line is blank, the http request has ended,
6366
// so you can send a reply
6467
if (c == '\n' && currentLineIsBlank) {
6568
// send a standard http response header
6669
client.println("HTTP/1.1 200 OK");
6770
client.println("Content-Type: text/html");
71+
client.println("Connnection: close");
6872
client.println();
73+
client.println("<!DOCTYPE HTML>");
6974
client.println("<html>");
75+
// add a meta refresh tag, so the browser pulls again every 5 seconds:
76+
client.println("<meta http-equiv=\"refresh\" content=\"5\">");
7077
// output the value of each analog input pin
7178
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
79+
int sensorReading = analogRead(analogChannel);
7280
client.print("analog input ");
7381
client.print(analogChannel);
7482
client.print(" is ");
75-
client.print(analogRead(analogChannel));
83+
client.print(sensorReading);
7684
client.println("<br />");
7785
}
7886
client.println("</html>");
79-
break;
87+
break;
8088
}
8189
if (c == '\n') {
8290
// you're starting a new line
@@ -90,8 +98,9 @@ void loop() {
9098
}
9199
// give the web browser time to receive the data
92100
delay(1);
93-
// close the connection:
94-
client.stop();
101+
// close the connection:
102+
client.stop();
103+
Serial.println("client disonnected");
95104
}
96105
}
97106

@@ -103,7 +112,7 @@ void printWifiStatus() {
103112

104113
// print your WiFi shield's IP address:
105114
IPAddress ip = WiFi.localIP();
106-
Serial.print("IP Address: ");
115+
Serial.print("IP Address: ");
107116
Serial.println(ip);
108117

109118
// print the received signal strength:
@@ -112,3 +121,4 @@ void printWifiStatus() {
112121
Serial.print(rssi);
113122
Serial.println(" dBm");
114123
}
124+

0 commit comments

Comments
 (0)