After identifying the delays in the ethernet card output operation while writing data to an online log file as the cause of problems I am experiencing, I created a simple test sketch.
The purpose for the test is to confirm that delays in the ethernet operation, is in fact causing problems (delays) with the rest of the sketch.
I believe that I have confirmed this, as running the test sketch, and then unplugging the ethernet cable from my router for a few seconds, I have simulated what would occur if there were internet delays or an internet connection failure.
The output in the Serial Monitor, which should change every 1 second, slowed down with delays of just over 2 seconds when the ethernet cable was unplugged.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,101);
IPAddress gateway(192,168,1,254);
IPAddress subnet(255,255,255,0);
IPAddress myserver(123,123,123,123);
EthernetServer server(82);
EthernetClient client;
long LastMil = 0;
void setup(){
pinMode(4, OUTPUT); //ETHERNET SETUP
Ethernet.begin(mac, ip, subnet, gateway);
server.begin();
Serial.begin(9600);
LogItWebC(1000);
Serial.println("Send an get1 in serial monitor to test client."); // what to do to test client
pinMode(16, OUTPUT);
pinMode(17, OUTPUT);
pinMode(18, OUTPUT);
LogItWebC(1001);
}
void loop(){
unsigned long currentMillis = millis();
if (currentMillis - LastMil >= 1000){
LogItWebC(currentMillis);
LastMil = currentMillis;
Serial.print("----------");
Serial.println(currentMillis);
}
} //end of LOOP
void LogItWebC(long LogTxt){
if (client.connect(myserver, 80)) {
client.print("GET http://www.xxx.com/serveittest.php?data=");
client.print("1----");
client.print(LogTxt);
client.println(" HTTP/1.1");
client.println("Host: www.xxx.com");
client.println();
delay(250);
client.stop();
Serial.print("1----");
Serial.println(LogTxt);
}
} // end of void LogItWebC()