13
13
14
14
created 13 July 2010
15
15
by dlf (Metodo2 srl)
16
- modified 4 Mar 2012
16
+ modified 20 Mar 2012
17
17
by Tom Igoe
18
18
*/
19
19
20
20
21
21
#include < SPI.h>
22
22
#include < WiFi.h>
23
23
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)
27
28
28
29
int status = WL_IDLE_STATUS;
29
30
@@ -53,30 +54,37 @@ void loop() {
53
54
// listen for incoming clients
54
55
WiFiClient client = server.available ();
55
56
if (client) {
57
+ Serial.println (" new client" );
56
58
// an http request ends with a blank line
57
59
boolean currentLineIsBlank = true ;
58
60
while (client.connected ()) {
59
61
if (client.available ()) {
60
62
char c = client.read ();
63
+ Serial.write (c);
61
64
// if you've gotten to the end of the line (received a newline
62
65
// character) and the line is blank, the http request has ended,
63
66
// so you can send a reply
64
67
if (c == ' \n ' && currentLineIsBlank) {
65
68
// send a standard http response header
66
69
client.println (" HTTP/1.1 200 OK" );
67
70
client.println (" Content-Type: text/html" );
71
+ client.println (" Connnection: close" );
68
72
client.println ();
73
+ client.println (" <!DOCTYPE HTML>" );
69
74
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\" >" );
70
77
// output the value of each analog input pin
71
78
for (int analogChannel = 0 ; analogChannel < 6 ; analogChannel++) {
79
+ int sensorReading = analogRead (analogChannel);
72
80
client.print (" analog input " );
73
81
client.print (analogChannel);
74
82
client.print (" is " );
75
- client.print (analogRead (analogChannel) );
83
+ client.print (sensorReading );
76
84
client.println (" <br />" );
77
85
}
78
86
client.println (" </html>" );
79
- break ;
87
+ break ;
80
88
}
81
89
if (c == ' \n ' ) {
82
90
// you're starting a new line
@@ -90,8 +98,9 @@ void loop() {
90
98
}
91
99
// give the web browser time to receive the data
92
100
delay (1 );
93
- // close the connection:
94
- client.stop ();
101
+ // close the connection:
102
+ client.stop ();
103
+ Serial.println (" client disonnected" );
95
104
}
96
105
}
97
106
@@ -103,7 +112,7 @@ void printWifiStatus() {
103
112
104
113
// print your WiFi shield's IP address:
105
114
IPAddress ip = WiFi.localIP ();
106
- Serial.print (" IP Address: " );
115
+ Serial.print (" IP Address: " );
107
116
Serial.println (ip);
108
117
109
118
// print the received signal strength:
@@ -112,3 +121,4 @@ void printWifiStatus() {
112
121
Serial.print (rssi);
113
122
Serial.println (" dBm" );
114
123
}
124
+
0 commit comments