I am finding that sometimes our DSL line is down ( ethernet shield connected to dsl router and router operating OK ) and my code is freezing.
I assume that this is caused by the ethernet library retrying until some timeout occurs, or more likely by incorrect code in my sketch that is not managing the retries.
Would the follow 2 extracts produce the same result, or would one be better at ignoring a DSL line fault than the other ?
The data I am sending out to my web site php script is only log data and is not critical. It is more important for the other code in my sketch to be able to run without interruptions / delays.
code 1 :
if (client.connect(myserver, 80)) {
client.print("GET http://www.abc.com/myscript.php?data=");
// make a string of all the codes to upload
for(int i = 0;i < 30;i++){
if(LogData[i] != 0){
client.print(LogData[i]);
client.print("-");
}
}
client.println(" HTTP/1.1");
client.println("Host: www.abc.com");
client.println();
delay(1);
client.stop();
}
code 2 :
EthernetClient WWWclient = server.available();
if (WWWclient) {
while (WWWclient.connected()) {
if (WWWclient.available()) {
client.print("GET http://www.abc.com/myscript.php?data=");
// make a string of all the codes to upload
for(int i = 0;i < 30;i++){
if(LogData[i] != 0){
client.print(LogData[i]);
client.print("-");
}
}
client.println(" HTTP/1.1");
client.println("Host: www.abc.com");
client.println();
delay(1);
WWWclient.stop();
}
}
}