1010
1111 created 18 Dec 2009
1212 by David A. Mellis
13- modified 4 Sep 2010
13+ modified 20 Mar 2012
1414 by Tom Igoe
1515
1616 */
2020
2121// Enter a MAC address and IP address for your controller below.
2222// 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 };
2425IPAddress ip (192 ,168 ,1 , 177 );
2526
2627// Initialize the Ethernet server library
2728// with the IP address and port you want to use
2829// (port 80 is default for HTTP):
2930EthernetServer server (80 );
3031
31- void setup ()
32- {
32+ void setup () {
33+ Serial. begin ( 9600 );
3334 // start the Ethernet connection and the server:
3435 Ethernet.begin (mac, ip);
3536 server.begin ();
37+ Serial.print (" server is at " );
38+ Serial.println (Ethernet.localIP ());
3639}
3740
38- void loop ()
39- {
41+
42+ void loop () {
4043 // listen for incoming clients
4144 EthernetClient client = server.available ();
4245 if (client) {
46+ Serial.println (" new client" );
4347 // an http request ends with a blank line
4448 boolean currentLineIsBlank = true ;
4549 while (client.connected ()) {
4650 if (client.available ()) {
4751 char c = client.read ();
52+ Serial.write (c);
4853 // if you've gotten to the end of the line (received a newline
4954 // character) and the line is blank, the http request has ended,
5055 // so you can send a reply
5156 if (c == ' \n ' && currentLineIsBlank) {
5257 // send a standard http response header
5358 client.println (" HTTP/1.1 200 OK" );
5459 client.println (" Content-Type: text/html" );
60+ client.println (" Connnection: close" );
5561 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\" >" );
5766 // output the value of each analog input pin
5867 for (int analogChannel = 0 ; analogChannel < 6 ; analogChannel++) {
68+ int sensorReading = analogRead (analogChannel);
5969 client.print (" analog input " );
6070 client.print (analogChannel);
6171 client.print (" is " );
62- client.print (analogRead (analogChannel) );
63- client.println (" <br />" );
72+ client.print (sensorReading );
73+ client.println (" <br />" );
6474 }
75+ client.println (" </html>" );
6576 break ;
6677 }
6778 if (c == ' \n ' ) {
@@ -78,5 +89,7 @@ void loop()
7889 delay (1 );
7990 // close the connection:
8091 client.stop ();
92+ Serial.println (" client disonnected" );
8193 }
8294}
95+
0 commit comments