!!!!!!!!### In attachments is a script that can control more one relay and display on IOS device. !!!!!!
// http://www.instructables.com/id/Arduino-WebServer-controlled-LED/step2/Create-HTML-Form/
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
EthernetServer server(80);
void setup()
{
Serial.begin(9600);
pinMode(8, OUTPUT);
Ethernet.begin(mac, ip);
server.begin();
}
if (digitalRead(8 )){
client.print(" LED is <font color='green'>ON</font>");
}else{
client.print(" LED is <font color='red'>OFF</font>");
}
client.println("
");
client.print("<FORM action=\"http://192.168.1.177/\" >");
client.print("<P> <INPUT type=\"radio\" name=\"status\" value=\"1\">ON");
client.print("<P> <INPUT type=\"radio\" name=\"status\" value=\"0\">OFF");
client.print("<P> <INPUT type=\"submit\" value=\"Submit\"> </FORM>");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
buffer="";
} else if (c == '\r') {
if(buffer.indexOf("GET /?status=1″)>=0)
digitalWrite(8,HIGH);
if(buffer.indexOf("GET /?status=0″)>=0)
digitalWrite(8,LOW);
}
else {
;D Another version ;D
#include <Ethernet.h>
#include <SPI.h>
boolean reading = false;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x49, 0xD6 };
byte ip[] = { 169,254,63,178 };
static char baseurl[]="http://169.254.63.178/";
Server server = Server(80); //port 80
void setup(){
//Pins 10,11,12 & 13 are used by the ethernet shield
pinMode(9, OUTPUT);
Ethernet.begin(mac, ip);
server.begin();
}
void loop(){
// listen for incoming clients, and process qequest.
checkForClient();
}
void checkForClient(){
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
boolean sentHeader = false;
while (client.connected()) {
if (client.available()) {
if(!sentHeader){
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("LED switch");
client.println("<form METHOD=get action=\"");
client.println(baseurl);
client.println("\">");
client.println("<input type=hidden name=LED value=0>");
client.println("<input type=submit value=\"off\"></form>");
client.println("<form METHOD=get action=\"");
client.println(baseurl);
client.println("\">");
client.println("<input type=hidden name=LED value=1>");
client.println("<input type=submit value=\"on\"></form>");
sentHeader = true;
}
char c = client.read();
if(reading && c == ' ') reading = false;
if(c == '?') reading = true; //found the ?, begin reading the info
if(reading){
Serial.print(c);
if(c == '0') {
digitalWrite(9, LOW);
break;
}
if(c == '1') {
digitalWrite(9, HIGH);
break;
}
}
if (c == '\n' && currentLineIsBlank) break;
if (c == '\n') {
currentLineIsBlank = true;
}else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection:
}
}