mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-10 21:24:12 +01:00
Updated Ethernet WebServer example to give more diagnostic info
This commit is contained in:
parent
a46facad70
commit
da09e0c867
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
created 18 Dec 2009
|
created 18 Dec 2009
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 4 Sep 2010
|
modified 20 Mar 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@ -20,7 +20,8 @@
|
|||||||
|
|
||||||
// Enter a MAC address and IP address for your controller below.
|
// Enter a MAC address and IP address for your controller below.
|
||||||
// The IP address will be dependent on your local network:
|
// The IP address will be dependent on your local network:
|
||||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
byte mac[] = {
|
||||||
|
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||||
IPAddress ip(192,168,1, 177);
|
IPAddress ip(192,168,1, 177);
|
||||||
|
|
||||||
// Initialize the Ethernet server library
|
// Initialize the Ethernet server library
|
||||||
@ -28,23 +29,27 @@ IPAddress ip(192,168,1, 177);
|
|||||||
// (port 80 is default for HTTP):
|
// (port 80 is default for HTTP):
|
||||||
EthernetServer server(80);
|
EthernetServer server(80);
|
||||||
|
|
||||||
void setup()
|
void setup() {
|
||||||
{
|
Serial.begin(9600);
|
||||||
// start the Ethernet connection and the server:
|
// start the Ethernet connection and the server:
|
||||||
Ethernet.begin(mac, ip);
|
Ethernet.begin(mac, ip);
|
||||||
server.begin();
|
server.begin();
|
||||||
|
Serial.print("server is at ");
|
||||||
|
Serial.println(Ethernet.localIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
void loop() {
|
||||||
// listen for incoming clients
|
// listen for incoming clients
|
||||||
EthernetClient client = server.available();
|
EthernetClient 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
|
||||||
@ -52,16 +57,22 @@ 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>");
|
||||||
|
// 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>");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
@ -78,5 +89,7 @@ void loop()
|
|||||||
delay(1);
|
delay(1);
|
||||||
// close the connection:
|
// close the connection:
|
||||||
client.stop();
|
client.stop();
|
||||||
|
Serial.println("client disonnected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user