First of all I thank people who have worked to build the Arduino Ethernet Shield and develop the Ethernet library.
Then I have 2 requests :
Could it be possible to have a more detailed documentation for the Ethernet library
Could it be possible to have a client example (quite the same as Client example) which request periodically the same page. I tried to modify Client example to do that but it doesn't work very well (half time connection fails).
Ok just to make it clear that I don't have any Arduino Ethernet shields but I will try and offer my assistance.
Briefly looking at your code, I can see a couple of errors that could be contributing to the unexpected events you are encountering.
The line:
client.println("User-Agent: AVR ethernet\r\n");
Should be:
client.println("User-Agent: AVR ethernet");
The extra carriage return and newline characters you have would cause the server to think you have completed your HTTP GET request.
You are disconnecting the Client at the wrong time. You should change your "if (client_state==STEP2)" block to be this (the yellow highlighted line is the line I changed):
if (client_state==STEP2)
{
if (client.available()) {
char c = client.read();
Serial.print(c);
client_state=STEP2;
}
[glow]else if (!client.connected())[/glow]
{ Serial.println();
Serial.println("disconnecting.");
client.stop();
delay(7000);
client_state=STEP1;
}
}
}
Thank you for these suggestions. It seems to work.
I've also discovered that it didn't work very well on one of my personal website but very well on another one.
It seems that my first personal website doesn't answer to each GET HTTP request. I don't know why ?
With my second personal website, I have 100% of success.