Help with Ehternet shield not responding

Hi, i'm new with programming with an ethernet shield (w5100)

I'm using the ethernet Librairy and my IDE is up-to-date.

I tried a good tutorial exemple about simply lighting up a led with a checkbox. ( LED Control with Arduino Ethernet Shield Web Server ) it worked great. I'm a web programmer so I wished to made an interface (css, no image) with basic link ( tage) instead of checkbox.

The tutorial was sending a parameter by a , each click change the state of the light.

With my link I send a parameter, exemple 192.168.1.10/?led=0 (or ?led=1, or simply no parameter). I have a "on" link and a "off" link.

My page did not respond everytime to those parameter. I explain:

  • I load my server main page: 192.168.1.10 in browser adresse bar
  • I click on the "on" link: url change for 192.168.1.10/?LED=1 and LED light up
  • I click on the "off" link: url change for 192.168.1.10/?LED=0 BUT LED is still light up
  • I click AGAIN on the "off" link: url didn't change because is already 192.168.1.10/?LED=0 AND LED turn of.

The "on" link always work on first time but "off" link always need two click ?

Is anyone can help me ?

There is a part of my code, but sorry, i made change and try a lot of thing. the code below do the same thing as a simple link, it send the parameter using a form and a submit button. It produce the same result as described

void loop()
{
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                HTTP_req += c;  // save the HTTP request 1 char at a time
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println();
                    // send web page
                    client.println("<!DOCTYPE html>");
                    client.println("<html>");
                    client.println("<head>");
                    client.println("<title>Controls Arduino</title>");
                    client.println("<link rel='stylesheet' href='http://www.  ....   /arduino/control.css' />");
                    client.println("</head>");
                    client.println("<body>");
                    client.println("


");
                    client.println("");
                    client.println("<center>");
                    
                    client.println("<table>");
                    
                    processRouge(client);                    
                    
                    client.println("</table>");
                    
                    client.println("</center>");
                    client.println("</body>");
                    client.println("</html>");
                    HTTP_req = "";    // finished with request, empty string
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}

void processRouge(EthernetClient cl){
  
  cl.println("<tr>");
  cl.println("<td><b>Red LED</b>


</td>");
  if (HTTP_req.indexOf("LED=1") > -1) {  // if we ask to light the led
    LEDrouge_status = 1;
  }
  if (HTTP_req.indexOf("LED=0") > -1) {  // if we ask to close the led
    LEDrouge_status = 0;
  }
  if (LEDrouge_status == 1){
    digitalWrite(pinLedRouge,HIGH);
    cl.println("<td><form method='get'><input type='hidden' id='LED' name='LED' value='0'/><span class='toggleBox'><input type='submit' value='open' class='isToggledON'><input type='submit' value='close' class='isNotToggled'></span>


</form></td>");
  }else{
    digitalWrite(pinLedRouge,LOW);
    cl.println("<td><form method='get'><input type='hidden' id='LED' name='LED' value='1'/><span class='toggleBox'><input type='submit' value='open' class='isNotToggled'><input type='submit' value='close' class='isToggledOFF'></span>


</form></td>");
  } 
  
  cl.println("</tr>");
}

I also tried to delay some millisecond to let the server some time, but the result is the same.

Any idea ?

I maybe found my problem but still need help:

I print on the serial screen the "HTTP_req" srting and realise both of the parameter was included. Quick exemple of the http_req string is

GET /?LED=0 HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Referer: http://192.168.0.103/?LED=1
Accept-Language: fr-CA
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: 192.168.0.103
DNT: 1
Connection: Keep-Alive

in my "processRouge()" function I test this http_req string to see if I found the wanted parameter but didn't know there was also a reference to the current page so there is the new parameter "LED=0" and the old "LED=1" further in the "referer" section... so this cause my "if" bloc to fail

Is someone can help me building up a good "if" bloc, to test the first line of the http_req ? I'm not so good in c++ and i dont really know all the string function i can use to isolate the first line.

How can i get every thing before the "HTTP" text ? OR is it easier to do this kind of If statement to test only the "get" parameter :

if (HTTP_req.indexOf("LED=1") > -1 AND HTTP_req.indexOf("LED=1") < HTTP_req.indexOf("HTTP")) {  // if LED=1 if found (index of 0 and +) and index before the "http" text
   LEDrouge_status = 1;
}

what should I do ?

THX

sorry i should had wrote && instead of AND in my if statement.

I am unable to send data to server, when I connect my Arduino uno directly to a router, it works fine when I connect hardware on my laptop Ethernet port and then bridge wi fi connection with it.

Error:
Failed to configure Ethernet using DHCP

@satyamkr80:
Please don't cross-post,
and don't hijack topics.
See http://forum.arduino.cc/index.php/topic,148850.0.html