I am using the following code to upload some log data (of events that have happened) to a web server based php script, which in turn records the received data into a log file.
All works 99.999999 %, except on a few rare occasions, my dsl connection to my ISP fails ( due to external reasons ), and then the code freezes for a very long time ( I think in the range of a few minutes ). Absolutely nothing on the board responds, which leads me to think that the ethernet board is locking-up the main loop while it tries, continually without success, to connect to the web server IP address. This extended delay / freeze is a problem for my application of the Arduino board. I need to reduce the freeze time and get back to the main loop.
Any idea as to what, in the code, is causing the freezing, and then how can I modify it to abort the upload if the connection does not exist ?
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#include <SD.h>
#include <EEPROM.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xAD, 0xAD, 0xBE, 0xBE, 0xFE, 0xFE}; //physical mac address
IPAddress ip(192,168,1,101); // ip in lan
IPAddress gateway(192,168,1,1); // internet access via router
IPAddress subnet(255,255,255,0); //subnet mask
IPAddress myserver(41,21,1,1); // web server IP address
EthernetServer server(82); //server port
EthernetClient client;
String readString;
// in the main loop if there has been no other activity for 4 seconds :
UploadLogData();
// and after the main loop
void UploadLogData(){
// check if data exists in the array
if (LogNext >= 1){
if (client.connect(myserver, 80)) {
client.print("GET http://www.xxx.co.za/xxx.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.xxx.co.za");
client.println();
delay(250);
client.stop();
}
ClearLogArray(); // separate code to clear the uploaded log data array
}
}