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..