Basic WebClient for controlling LED

Hello,
I want to control 2 LEDs with using my html page(webb.html). I read the tutorials and created a system.
My simple html page's code;

<!DOCTYPE html>
<html>
<body>     
          <FORM >
          <P> <INPUT type="radio" name="status" value="1">ON
          <P> <INPUT type="radio" name="status" value="0">OFF
          

          

          <P> <INPUT type="radio" name="status" value="2">ON
          <P> <INPUT type="radio" name="status" value="3">OFF
          <P> <INPUT type="submit" value="Submit"> </FORM>
</body>
</html>

My arduino code;

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(myserverIp); 

IPAddress ip(192,168,1,4);

EthernetClient client;

void setup() {
  
  Serial.begin(9600);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
   
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    
    Ethernet.begin(mac, ip);
  }
  
  delay(1000);
  
  Serial.println("connecting...");

  if (client.connect(server, 80)) 
  {
    Serial.println("connected");
    client.println("GET /webb.html HTTP/1.1 200 OK");
    client.println("Host: www.myhost.net");
    client.println("Connection: close");
    client.println();
  }
  else 
  {
    Serial.println("connection failed");
  }
}

void loop()
{
  while (client.connected()) {
  if (client.available()) 
  {
    boolean currentLineIsBlank = true;
    String buffer = "";
    char c = client.read();
    Serial.print(c);
    buffer+=c;
      
    if (c == '\n') {
          
          currentLineIsBlank = true;
          buffer="";       
        } else if (c == '\r') {            
          if(buffer.indexOf("GET /?status=1")>=0)
            digitalWrite(3,HIGH);  
          
          if(buffer.indexOf("GET /?status=0")>=0)
            digitalWrite(3,LOW);
           
            
          if(buffer.indexOf("GET /?status=2")>=0)
            digitalWrite(4,HIGH);
            
          if(buffer.indexOf("GET /?status=3")>=0)
            digitalWrite(4,LOW); 
        }
        else {
          
          currentLineIsBlank = false;
        }
  }

  if (!client.connected()) 
  {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    while(true);
  }
  }
}

And when i upload this code to my arduino, i get this in serial monitor;

connecting...
connected
HTTP/1.1 200 OK
Date: Fri, 24 May 2013 23:37:59 GMT
Server: Apache/2.2.3 (Red Hat)
Last-Modified: Fri, 24 May 2013 22:12:05 GMT
ETag: "ba41800-1b4-4dd7e16cd1740"
Accept-Ranges: bytes
Content-Length: 436
Vary: Accept-Encoding
X-Powered-By: PleskLin
Connection: close
Content-Type: text/html

<!DOCTYPE HTML>
<body>     
          <FORM >
          <P> <INPUT type="radio" name="status" value="1">ON
          <P> <INPUT type="radio" name="status" value="0">OFF
          

          

          <P> <INPUT type="radio" name="status" value="2">ON
          <P> <INPUT type="radio" name="status" value="3">OFF
          <P> <INPUT type="submit" value="Submit"> </FORM>
</body>
</HTML>
              
disconnecting.

When I choose first radio on my html page to set my pin3 to turn on the LED, i can't get any result.
What am i missing? Or where did i make mistake?

Please help me to fix this.

Best Regards..

Hi, :slight_smile:
I am interested to do this project to see the error, but I have the same problem as you, if not evil declare my website or my ip. You have the solution

For starters, the two radio button groups cannot have the same name. One could be status, the other status1 for example.

You have a more fundamental problem however. Your get request from your arduino is asking for the webpage. It is effectively making the arduino operate as a browser, so you get the information necessary to display the webpage on the arduino.

Your get request has to be fullfilled by your server by reading the current state of some data . That data can be independently set by your browser showing the radio buttons. Pressing submit on the browser has to store the variables somewhere, which are then read later on by the get request from your arduino. Your would have to store the data somewhere on the server, like a file or an SQL database which gets written by your browser, and read by a get request processed by the server.

For a quick test, just change your webb.html to only contain "GET /?status=1" (or 0,2,3) to test your basic functionality, and demonstrate what you need to do.