Code freezes if dsl line is down

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();
      }
    }
  }
        client.print("GET http://www.abc.com/myscript.php?data=");

That's not a valid GET request.

Hi Paul

Why is it not valid ?

The data being passed to the php script is assembled in the 'for' loop, and it is definitely working with this code.

Why is it not valid ?

You've already connected to the server. The protocol to use is known. So, the "http://" part doesn't belong in the GET request, nor does the server name.

If your code uses dns to resolve the domain name of the server, the dns server is not localnet, and the dsl is down, that code will never connect. If the internet part is down, the length of the delay will not matter. If your code can't connect, it can't connect.

Actually, you are lucky. Normally PaulS will refer you to http://www.snippets-r-us.com. Please post all your code.

SurferTim:
If your code uses dns to resolve the domain name of the server, the dns server is not localnet, and the dsl is down, that code will never connect. If the internet part is down, the length of the delay will not matter. If your code can't connect, it can't connect.

Thanks SurferTim

The setup in my code contains :

char serverName[] = "http://www.abc.com";
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
IPAddress ip(192,168,1,101); // ip in lan
IPAddress gateway(192,168,1,254); // internet access via router
IPAddress subnet(255,255,255,0); //subnet mask
IPAddress myserver(11,11,18,70); //my web server ip
EthernetServer server(82); //server port
EthernetClient client;
String readString; 

Ethernet.begin(mac, ip, subnet, gateway); 
server.begin();

but I think maybe I have not made my question clear.

So here it is re-worded : is there any way to check if a dsl connection exists, that is not subject to any time delays / timeouts, or any way to ping a server with a set maximum timeout ? That way I could ping my web server first, and if that does not respond within, for example, 100ms, then assume that the dsl line is down ( or the web server is down ) and move on with the rest of the sketch without wasting time ( and delaying sketch code execution ) waiting for the connection to time-out ?

There are a couple things are not correct.

  1. Do not use the protocol on the server name
// change this...
char serverName[] = "http://www.abc.com";
...to this
char serverName[] = "www.abc.com";
  1. This has the wrong parameters.
// change this...
Ethernet.begin(mac, ip, subnet, gateway);
...to this
Ethernet.begin(mac, ip, gateway, gateway, subnet);

The first gateway is actually the dns server. If you are using dns and a dns server, specify that in your network stuff and use it there. Like this:

IPAddress dnServer(1,2,3,4);

Ethernet.begin(mac, ip, dnServer, gateway, subnet);

Thanks SurferTim. Appreciate the pointers.

I came across this site http://biskandar.com/2012/10/10/make-your-arduino-talks-to-the-world/ and used the code to add a ping check to my sketch.

So whenever I want to upload the log data, I first run the ping ( all 2 lines of code ) and if the ping returns "Request Timed Out" then I skip the log upload for 1 minute and then try again.

The ping appears really fast ( compared to trying to 'connect' to a web server ) so it has little effect on the execution of the rest of the code.

Thanks to all for the help.