10
10
11
11
created 18 Dec 2009
12
12
by David A. Mellis
13
- modified 4 Sep 2010
13
+ modified 20 Mar 2012
14
14
by Tom Igoe
15
15
16
16
*/
20
20
21
21
// Enter a MAC address and IP address for your controller below.
22
22
// The IP address will be dependent on your local network:
23
- byte mac[] = { 0xDE , 0xAD , 0xBE , 0xEF , 0xFE , 0xED };
23
+ byte mac[] = {
24
+ 0xDE , 0xAD , 0xBE , 0xEF , 0xFE , 0xED };
24
25
IPAddress ip (192 ,168 ,1 , 177 );
25
26
26
27
// Initialize the Ethernet server library
27
28
// with the IP address and port you want to use
28
29
// (port 80 is default for HTTP):
29
30
EthernetServer server (80 );
30
31
31
- void setup ()
32
- {
32
+ void setup () {
33
+ Serial. begin ( 9600 );
33
34
// start the Ethernet connection and the server:
34
35
Ethernet.begin (mac, ip);
35
36
server.begin ();
37
+ Serial.print (" server is at " );
38
+ Serial.println (Ethernet.localIP ());
36
39
}
37
40
38
- void loop ()
39
- {
41
+
42
+ void loop () {
40
43
// listen for incoming clients
41
44
EthernetClient client = server.available ();
42
45
if (client) {
46
+ Serial.println (" new client" );
43
47
// an http request ends with a blank line
44
48
boolean currentLineIsBlank = true ;
45
49
while (client.connected ()) {
46
50
if (client.available ()) {
47
51
char c = client.read ();
52
+ Serial.write (c);
48
53
// if you've gotten to the end of the line (received a newline
49
54
// character) and the line is blank, the http request has ended,
50
55
// so you can send a reply
51
56
if (c == ' \n ' && currentLineIsBlank) {
52
57
// send a standard http response header
53
58
client.println (" HTTP/1.1 200 OK" );
54
59
client.println (" Content-Type: text/html" );
60
+ client.println (" Connnection: close" );
55
61
client.println ();
56
-
62
+ client.println (" <!DOCTYPE HTML>" );
63
+ client.println (" <html>" );
64
+ // add a meta refresh tag, so the browser pulls again every 5 seconds:
65
+ client.println (" <meta http-equiv=\" refresh\" content=\" 5\" >" );
57
66
// output the value of each analog input pin
58
67
for (int analogChannel = 0 ; analogChannel < 6 ; analogChannel++) {
68
+ int sensorReading = analogRead (analogChannel);
59
69
client.print (" analog input " );
60
70
client.print (analogChannel);
61
71
client.print (" is " );
62
- client.print (analogRead (analogChannel) );
63
- client.println (" <br />" );
72
+ client.print (sensorReading );
73
+ client.println (" <br />" );
64
74
}
75
+ client.println (" </html>" );
65
76
break ;
66
77
}
67
78
if (c == ' \n ' ) {
@@ -78,5 +89,7 @@ void loop()
78
89
delay (1 );
79
90
// close the connection:
80
91
client.stop ();
92
+ Serial.println (" client disonnected" );
81
93
}
82
94
}
95
+
0 commit comments