Ehternet shield

Hi,

This is my code for responding from command send from my browser. If I type 208.192.17.141/$22, some light will open and there is couple of other command.

THen, the arduino will send back some data over ethernet to create a new page, with some data.

During this time, nothing else on my arduino is running, not even the status light. I have toi close the new tab my arduino created in my browser so he could run again and receive new command.

Is there a way I can overcome this?? I would like to run the rest of the code, like status light and other things during this time.

Have any idea how?

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

int number=0;
int time_1, time_2, time=0;
double up_time1, up_time2, up_time,upv;

// Adress variable
int four = 23, four_d = 23;
int three = 25, three_d = 25;
int two = 27,two_d = 27;
int one = 29, one_d = 29;
int adress, adress_2;
// END adress variable

//Sensors variable
float temp_bedroom=20.25;
float temp_kitchen=20.25;
float temp_washroom=20.25;
float temp_living=20.25;
//END sensors variable

// System status variable
int status_led = 22;
int sys_status=0;
// END System status variable

// Command over ethernet variable
boolean incoming = 0;
// END Command over ethernet variable

// Spam_block variable
int command;
int array[31];
int task=0;
int task_result =0;
// END Spam_block variable


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 };
IPAddress ip(208,92,17,141); //<<< ENTER YOUR IP ADDRESS HERE!!!

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);


void setup()
{
    // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.begin(9600);
  up_time1 = millis();
}

void loop()
{

  command_over_ethernet();
  led_status();
 
}

void command_over_ethernet()
{

  // listen for incoming clients
  
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {

        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply

        //reads URL string from $ to first blank space
        if(incoming && c == ' '){

          incoming = 0;
        }
        if(c == '

Thanks

****There is some missing parts of the code due to lenght (9500 max)

){

incoming = 1;
       }

//Checks for the URL string $1 or $2
       if(incoming == 1){

char c = client.read();

//-------------------------------------------------------//
         //Receive second code------------------------------------//
         //-------------------------------------------------------//
         if(c == ‘2’){
             //Serial.println(“ON”);
             //digitalWrite(2, LOW);
 
             char c = client.read();
         //-------------------------------------------------------//
         //Send sensors status------------------------------------//
         //-------------------------------------------------------//
             if(c == ‘0’){
               //Serial.println(“OFF”);
               //delay(10);
               //digitalWrite(2, LOW);
               Serial.println(“Command 20”);
               Serial.println(“Send sensors status”);
               client.println(“Command 20”);
               client.println(“Send sensors status”);
               client.println("//------------------------------//");
               
               time_1 = millis();
               
               client.println(“Bedroom temperature”);
               client.println(temp_bedroom);
               client.println("…");
               
               client.println(“Living room temperature”);
               client.println(temp_living);
               client.println("…");
               
               client.println(“Washroom temperature”);
               client.println(temp_washroom);
               client.println("…");
               
               client.println(“Kitchen temperature”);
               client.println(temp_kitchen);
               client.println("…");
               
               adress_2 = adress_value();
               client.println(“Arduino adress”);
               client.println(adress);
               client.println("…");
               
               client.println(“Up time”);
               upv = get_up_time();
               upv = upv /1000;
               upv = upv /60;
               client.println(upv);
               client.println(“Minutes”);
               upv = upv /60;
               client.println(upv);
               client.println(“Hours”);
               client.println("…");
               
               time_2=millis();
               time = time_2 - time_1;
               
               client.println(“Task executed in”);
               client.println(time);
               client.println(“Milliseconds”);
               
             }
           //-------------------------------------------------------//
           //Fermer le néon des plante------------------------------//
           //-------------------------------------------------------//          
             if(c == ‘1’){
               time_1 = millis();
               //Serial.println(“OFF”);
               Serial.println(“Commande 21”);
               task_result = spam_block(21,client);
 
               if(task_result == 1){
                 light_off();
                 time_2=millis();
                 client.println(“Light have been closed”);
                 time = time_2 - time_1;
                 client.println(time);
                 client.println(“Milliseconds”);
                 array[22]=0;
               }
             }
           //-------------------------------------------------------//
           //Allumer le néon des plantes----------------------------//
           //-------------------------------------------------------//
             if(c == ‘2’){
               time_1 = millis();
               number = 22;
               //Serial.println(“OFF”);
               Serial.println(“Commande 22”);
               task_result = spam_block(number,client);
               show_IP_ADRESS();
 
               if(task_result == 1){
                 light_on();
                 time_2=millis();
                 client.println(“Light have been opened”);
                 time = time_2 - time_1;
                 client.println(time);
                 client.println(“Milliseconds”);
                 array[number-1]=0;
               }
             }
           //-------------------------------------------------------//        
 
             break;
         }

}

if (c == ‘\n’) {
         // you’re starting a new line
         currentLineIsBlank = true;
       }
       else if (c != ‘\r’) {
         // you’ve gotten a character on the current line
         currentLineIsBlank = false;
       }
     }
   }
   // give the web browser time to receive the data
   delay(1);
   // close the connection:
   client.stop();
 }
}

void led_status(){

sys_status++;

if (sys_status <=1600){
   digitalWrite(status_led, LOW);
 }
 if (sys_status >1600){
   digitalWrite(status_led, HIGH);
 }
 if (sys_status >=3200){
   sys_status = 0;
   digitalWrite(status_led, LOW);
 }

}


Thanks

****There is some missing parts of the code due to lenght (9500 max)
int four = 23;

WTF?

double up_time1;
  up_time1 = millis();

Fail! The millis() does not return a double. Never has. Never will.

boolean incoming = 0;
        if(incoming && c == ' '){

          incoming = 0;
        }
        if(c == '

Boolean variables get set to true or false.

          char c = client.read();

          //-------------------------------------------------------//
          //Receive second code------------------------------------//
          //-------------------------------------------------------// 
          if(c == '2'){
              //Serial.println("ON");
              //digitalWrite(2, LOW);
  
              char c = client.read();

Some reason you need two local variables named c?

Make a copy of your code. Delete everything but the client.print() statements. Is there any way that you can arrange them into a meaningful web page?){

incoming = 1;
        }


Boolean variables get set to true or false.

§DISCOURSE_HOISTED_CODE_3§


Some reason you need two local variables named c?

Make a copy of your code. Delete everything but the client.print() statements. Is there any way that you can arrange them into a meaningful web page?