Hello to all,
this is my first post (as I have the arduino only since one week now).
I have a Arduino Mega with ethernet shield and arduino-0022 SW, but the Webserver-Example does not work.
The web browser keeps waiting for an answer, that does not come.
I changed the example to echo whatever comes in at the arduino:
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,0, 111 };
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
Server server(80);
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
delay(1000);
blink();
}
void loop()
{
// listen for incoming clients
Client client = server.available();
if (client) {
blink();
client.println("HTTP/1.0 200 OK");
client.println("Content-Type: text/plain");
client.println();
// an http request ends with a blank line
boolean currentLineIsBlank = true;
int i = 0;
while (client.connected()) {
if (client.available()) {
blink2();
char c = client.read();
client.print(c);
i++;
if (i > 2000) {
break;
}
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
//client.println("HTTP/1.0 200 OK");
//client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("
");
}
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
void blink() {
digitalWrite(13, HIGH); // set the LED on
delay(200); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(500); // wait for a second
}
void blink2() {
digitalWrite(13, HIGH); // set the LED on
delay(60); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(60); // wait for a second
}
And this is, what comes in in the browser window now:
GET /index.html HTTP/1.1
Host: 192.168.0.111
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20110107 Iceweasel/3.5.16 (like Firefox/3.5.16)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language:GET /index.html HTTP/1.1
Host: 192.168.0.111
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20110107 Iceweasel/3.5.16 (like Firefox/3.5.16)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language:GET /index.html HTTP/1.1
Host: 192.168.0.111
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20110107 Iceweasel/3.5.16 (like Firefox/3.5.16)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language:GET /index.html HTTP/1.1
[...and.so.on.and.so.on...]
Conclusion 1: The example software never "sees" an empty line, and so never starts to send the HTTP response.
Conclusion 2: My first thought was, that the web browser is re-sending its request over and over due some socket state problem or so, but then I realized, that the reading from internal read buffer in the w5100 chip is always starting to read from the beginning.
(I noticed in W5100Class::recv_data_processing
the lines
ptr += len;
writeSnRX_RD(s, ptr);
which should actually do it.)
My main questions for now are:
- Why is nobody else reporting problems with the Ethernet library or Server example?
- Can anybody confirm this problem?
(Who knows, maybe it turns out to be a somehow broken ethernet shield after all.)
Thanks in advance for any suggestions.