Pages: [1]   Go Down
Author Topic: Ethernet Shield Time Between Requests  (Read 269 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
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?
Logged

Harlow, Essex, UK
Offline Offline
Jr. Member
**
Karma: 1
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this, I'm very new to Arduinos but this is similar to what I have and works fine:

Code:
if (client.connect()) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /flow?freq=30 HTTP/1.0");
    client.println("Connection: close"); // not totally sure if i need this?
    client.println();
    delay(1000);
  } else {
    Serial.println("connection failed");
  }
    delay(1000);

  if (!client.connected()) {
    Serial.println("disconnecting from server");
    client.stop();
    client.flush();
    Serial.println("Disconnected...");
  }
}
Logged

Pages: [1]   Go Up
Jump to: