I am attempting to use the ethernet shield to post data from a sensor to a url. I can only get the arduino to send a request about once every 30 seconds though. Here is the code I am using:
void setup() {
// start the Ethernet connection:
Ethernet.begin(mac, ip);
delay(1000);
pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
Serial.begin(9600); //This is the setup function where the serial port is initialised,
attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}
void loop()
{
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a new line
if (client.connect()) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /flow?freq=30 HTTP/1.0");
client.println("Connection: Keep-Alive"); // not totally sure if i need this?
client.println();
} else {
Serial.println("connection failed");
}
delay(1000);
client.flush();
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
} else {
client.stop();
}
}
This does the repeated requests successfully, but hangs for about 30 seconds just before the call to client.connected() each time. The page I am requesting returns an empty response so it can't be that the response is hanging from the server. I've read about people having problems with the socket not getting closed properly so they just have to wait for it to time out which takes about 30 seconds. Could this be that issue?