Wifly shield read from database every 10 seconds

Hello. I'm a newbie in arduino.
I'm trying to make the wifly shield read from a local database every ten seconds. I managed to do this by using a conditional if in the millis() and adding the value I wanted to wait until it loaded again to a variable like this:

if (millis() >= updateTime) {
updateTime += 10000;
}

the problem I'm having is that the arduino reads from the database and "updates" 2 times and then it stops.

this is my code

#include <_Spi.h>
#include <Client.h>
#include <Configuration.h>
#include <Debug.h>
#include <ParsedStream.h>
#include <Server.h>
#include <SpiUart.h>
#include <WiFly.h>
#include <WiFlyDevice.h>

// (Based on Ethernet's WebClient Example)

#include "WiFly.h"


#include "Credentials.h"


//byte server[] = { 194,80,29,91 }; // Google
//byte server[] = { 66, 249, 89, 104 }; // Google
byte server[] = {169,254,195,202 }; // Google

Client client(server, 80);
char c ;

int updateTime = 0;
int redPin =  3;    // LED connected to digital pin 13
int greenPin =  5;    // LED connected to digital pin 13
int bluePin =  6;    // LED connected to digital pin 13

//Client client("169.254.97.89/emotize", 80);
//Client client("http://www.google.com", 80);
//Client client("http://www.sandrobrt..com", 80);

void setup() {
  //------- for LED
  
  pinMode(redPin, OUTPUT);    
  pinMode(greenPin, OUTPUT);    
  pinMode(bluePin, OUTPUT);    
  
  
  // ---- for Wifi
  
  
  Serial.begin(115200);
  Serial.println("WebClient example at 38400 baud.");

  WiFly.begin();

  if (!WiFly.join(ssid)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  }  

  WiFly.configure(WIFLY_BAUD, 38400);

  Serial.println("connecting...");

  if (client.connect()) {
    Serial.println("connected");

    client.println("GET /get2.php?id_reciever=2 HTTP/1.0");

    client.println();
  } else {
    Serial.println("connection failed");
  }
  
}

int count = 0;
int plus = 0;

void loop() {
if (millis() >= updateTime) {
    client.flush();
    client.stop();
    WiFly.begin();
     if (!WiFly.join(ssid)) {
    Serial.println("Association failed.");
  }  
  WiFly.configure(WIFLY_BAUD, 38400);
  Serial.println("connecting...");
  if (client.connect()) {
    Serial.println("connected");
 
    client.println("GET /get2.php?id_reciever=2 HTTP/1.0");
    client.println();
  }else {
    Serial.println("connection failed");
  }

    updateTime += 10000;
  }
      current_state();
}


void current_state(){
    if (client.available()) {
     c = client.read();
    Serial.print(c);
    count++;

  }
   if(isDigit(c)) {
//            Serial.println(c);
    int number = int(c);
//  Serial.println(number);

    if(number == 49){//1
        analogWrite(redPin,0);
        analogWrite(greenPin,0);
        analogWrite(bluePin,0);
        analogWrite(redPin, 255);
        analogWrite(bluePin, 100);
     }
       if(number == 50){ //2
        analogWrite(redPin,0);
        analogWrite(greenPin,0);
        analogWrite(bluePin,0);
        analogWrite(redPin, 255);
        analogWrite(greenPin, 75);
     }
       if(number == 51){//3
        analogWrite(redPin,0);
        analogWrite(greenPin,0);
        analogWrite(bluePin,0);
        analogWrite(bluePin, 255);
     }
       if(number == 52){//4
        analogWrite(redPin,0);
        analogWrite(greenPin,0);
        analogWrite(bluePin,0);
        analogWrite(redPin, 255);
     }
       if(number == 53){//5
        analogWrite(redPin,0);
        analogWrite(greenPin,0);
        analogWrite(bluePin,0);
        analogWrite(greenPin, 255);
     }
       if(number == 54){//6
        analogWrite(redPin,0);
        analogWrite(greenPin,0);
        analogWrite(bluePin,0);
        analogWrite(redPin, 255);
        analogWrite(bluePin, 255);
        
     }
     
 

//  plus = 0;
//  }
  
    }
  
  
  
//  
//  if (!client.connected()) {
//    Serial.println();
//    Serial.println("disconnecting.");
//    client.stop();
//    for(;;)
//      ;
//  }

}

If someone knows what the problem is let me know please.

I tried to use the client.flush() because I guess that it's just saving unnecessary data but with it the program doesn't run properly.

thanks in advanced

Sandro Brito

int updateTime = 0;

After 1 iteration, updateTime will be 10000. After 2 iterations, updateTime will be 20000. After 3 iterations, updateTime will be 30000. After 4 iterations, updateTime will be 40000. Right? Wrong.

The updateTime variable will overflow when you add 10000 to 30000, since the largest value that can be stored in an int is 32,767.

Anyway, your approach to setting a future update time is wrong. What you need to do, instead, is record when the last update occurred, and use this time, and "now" to determine if it is time to do something again.

unsigned long lastTime = 0;
const unsigned long interval = 10000;

unsigned long currTime = millis();
if(currTime - lastTime > interval)
{
   // Do something

   lastTime = currTime;
}

I tried to use the client.flush() because I guess that it's just saving unnecessary data but with it the program doesn't run properly.

The client.flush() function dumps any data that the server has sent that the client has not yet read. You asked the server for some data. Why do you now want to throw the data away?

Thanks a lot. I'm going to try it now. I didn't know about the largest value being that.
As for the client.flush() it was because I thought the reason was because it was saving the data from before... stupid assumption.

Thanks again.