HTTP Request inside a loop

Hello.
I’m using the code below to send the value of some analogue inputs to a webserver and then place the values in a database. The code works fine, but the values are only send once (when the arduino boots).
What i need is to send the values at regular intervals (inside the loop() ). I tried several ways but to no avail.
Is there a way to do this?
Thanks.

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
 IPAddress server(55,55,55,55); // My site

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
 EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
   Serial.begin(9600);
   
   // start the Ethernet connection:
   if (Ethernet.begin(mac) == 0) {
     Serial.println("Failed to configure Ethernet using DHCP");
     // no point in carrying on, so do nothing forevermore:
     for(;;);
   }
   // give the Ethernet shield a second to initialize:
   delay(1000);
   Serial.println("connecting...");

   // if you get a connection, report back via serial:
   if (client.connect(server, 80)) {
     Serial.println("connected");
     // Make a HTTP request: 
     
        int temperatura=analogRead(0);
        int humidade=analogRead(1);
        
	// Make a HTTP request:
	client.print("GET http://www.mysite.com/ethernet.php?temperatura=");
        client.print(temperatura);
        client.print("&humidade=");
        client.print(humidade);
	client.println(" HTTP/1.1");
	client.println("Host: www.mysite.com");      
        client.println();
   } 
   else {
     // kf you didn't get a connection to the server:
     Serial.println("connection failed");
   }
}

void loop()
{
   // if there are incoming bytes available 
   // from the server, read them and print them:
   if (client.available()) {
     char c = client.read();
     Serial.print(c);
   }

   // if the server's disconnected, stop the client:
   if (!client.connected()) {
     Serial.println();
     Serial.println("disconnecting.");
     client.stop();


//do nothing forevermore:
for(;;);



   }
}

This code downloads Google home page every 10 seconds.

Change to your server as soon as you find it works. Don’t punish Google with your test. :wink:

check the blink without delay example...

Client test code that sends a get request to a web server based on an event, in this case an “e” received via the arduino serial port.

//zoomkat 4-04-12
//simple client test 
//for use with IDE 1.0
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605 
//the arduino lan IP address { 192, 168, 1, 102 } may need 
//to be modified modified to work with your router.

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan assigned to arduino
//byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
//byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
byte myserver[] = { 208, 104, 2, 86 }; // zoomkat web page server IP address
EthernetClient client;
//////////////////////

void setup(){

  Ethernet.begin(mac, ip);
  //Ethernet.begin(mac, ip, gateway, gateway, subnet);
  Serial.begin(9600); 
  Serial.println("Better client test 4/04/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(myserver, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

Thanks zoomkat. You code was exactly what i needed to find out a way to do it. Everything works perfectly now XD
Thanks a lot guys.