/*
Created by Rui Santos
Visit: http://randomnerdtutorials.com for more arduino projects
Arduino with Ethernet Shield
*/
#include <SPI.h>
#include <Ethernet.h>
int led = 9;
int count = 0;
boolean BoilerON = false;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 150 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(6882); //server port
String readString;
void setup(){
pinMode(9, OUTPUT); //pin selected to control
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.begin(9600);
delay(1000);
Serial.println("server LED test 1.0"); // so I can keep track of what is loaded
digitalWrite(led, LOW);
}
void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
client.println("<link rel='stylesheet' type='text/css' href='http://randomnerdtutorials.com/ethernetcss.css' />");
client.println("<TITLE>Yakov's Boiler</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Boiler</H1>");
if (BoilerON==true)
{
client.println("<td align='center'><font color='green' size='5'>status: ON");
client.println("<hr />");
client.println("
");
client.println("<a href=\"/?button1off\"\">Turn off</a>
");
}
else
{
client.println("<td align='center'><font color='black' size='5'>status: OFF");
client.println("<hr />");
client.println("
");
client.println("<a href=\"/?button1on\"\">Turn On</a>
");
}
client.println("
");
client.println("
");
client.println("<p>Shani Yakov</p>");
client.println("
");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
//controls the Arduino if you press the buttons
if (readString.indexOf("?button1on") >0)
{
digitalWrite(led, HIGH);
BoilerON = true;
}
if (readString.indexOf("?button1off") >0)
{
digitalWrite(led, LOW);
BoilerON = false;
}
//clearing string for next read
readString="";
}
}
}
}
}