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 ?