Go Down

Topic: Webserver problem (Read 698 times) previous topic - next topic

jozzy

So i've been trying to figure out what i've done wrong for almost 4 hours now, and i still didnt fixed it.
The problem is: i got 4 leds, but when i try to put led 1 on, all go on..
And when i put led 1 off, led 1 goes off, and rest stay on..
But if i want to put led 2 off after that led 1 goes on!!
So: all other leds goes on whatever i do!!

Here is the part of the code with the problem:

Code: [Select]

Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
c = client.read();
if (readString.length() < 30) {
readString.concat(c); }
if (c == '\n') { 
Le = readString.indexOf("L=");
if (Le > 1){ 
 
// LED1 //

  if (readString.substring(Le,(Le+5))== "L=1on");{
    digitalWrite(LED1, HIGH);
    LED1CHECK = true;}
  if (readString.substring(Le,(Le+6))== "L=1off"){
    digitalWrite(LED1, LOW);
    LED1CHECK = false;}

// LED2 //
   
  if (readString.substring(Le,(Le+5))== "L=2on");{
    digitalWrite(LED2, HIGH);
    LED2CHECK = true;}
  if (readString.substring(Le,(Le+6))== "L=2off"){
    digitalWrite(LED2, LOW);
    LED2CHECK = false;}


....


client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();

// LED1 //

client.println("<form method=get name=LED1>");
client.println("<font size='10'>LED status: ");
if (LED1CHECK == true){
Serial.println("LED1 is aan");
client.println("<font color='green' size='10'>ON</font>");
client.println("<input type='submit' name='L' value='1off' style='width: 50%; height: 15%; font:50px;'></form>");}
if (LED1CHECK == false){
Serial.println("LED1 is uit");
client.println("<font color='grey' size='10'>OFF</font>");
client.println("<input type='submit' name='L' value='1on' style='width: 50%; height: 15%; font:50px;'></form>");}

// LED2 //

client.println("<form method=get name=LED2>");
client.println("<font size='10'>LED status: ");
if (LED2CHECK == true){
Serial.println("LED2 is aan");
client.println("<font color='green' size='10'>ON</font>");
client.println("<input type='submit' name='L' value='2off' style='width: 50%; height: 15%; font:50px;'></form>");}
if (LED2CHECK == false){
Serial.println("LED2 is uit");
client.println("<font color='grey' size='10'>OFF</font>");
client.println("<input type='submit' name='L' value='2on' style='width: 50%; height: 15%; font:50px;'></form>");}


Im almost sure its an easy mistake, but i just cant find it

Thanks a lot in advance!!

jozzy

I dont know why it works now but i changed every second if into an else if and it worked T_T
Thnx anyway guys!!

Go Up