Hi can someone please help me not sure what i`m missing just cant get the status of the pin next to the buttons nearly there tho thanks
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x21, 0xE3 }; // MAC address from Ethernet shield sticker under board
IPAddress ip(192,168,1,67); // IP address, may need to change depending on network
byte gateway[] = { 192, 168, 1, 254 }; //Routers IP Address to which your shield is connected.
byte subnet[] = { 255, 255, 255, 0 }; //It will be as it is in most of the cases
EthernetServer server(80); //create a server at port 80
String readString;
// constants won't change. They're used here to set pin numbers:
const int shed_light_relay = 36; //shed light relay set on pin 36
const int heating_relay = 22; //Heating relay set on pin 25
const int shed_lock_relay = 7; //shed lock relay set on pin 7
// variables will change
int shed_light_relay_state = 0; // state of shed light relay, off by default at start/reset/power on
int heating_relay_state = 0; // state of heating relay, off by default at start/reset/power on
int shed_lock_state = 0; // state of shed lock relay, off by default at start/reset/power on
void setup(){
//pins selected to control
pinMode(shed_light_relay, OUTPUT); //shed light pin set as output
pinMode(heating_relay, OUTPUT); //heating pin set as output
pinMode(shed_lock_relay, OUTPUT); //shed lock pin set as output
//start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();
//enable serial data print
Serial.begin(9600);
}
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
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("<TITLE>Home Automation</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<meta name='viewport' content='width=device-width'; initial-scale=1.0; maximum-scale=1.0;>"); //size page for mobile devices
client.println("<h1>Shed Light</h1>");
client.print("<input type=submit value=ON style=width:100px;height:45px onClick=location.href='/?on4'>");
client.print(" <input type=submit value=OFF style=width:100px;height:45px onClick=location.href='/?off5'>");
client.println("<h1>Heating</h1>");
client.print("<input type=submit value=ON style=width:100px;height:45px onClick=location.href='/?on6'>");
client.print(" <input type=submit value=OFF style=width:100px;height:45px onClick=location.href='/?off7'>");
client.println("<h1>shed lock</h1>");
client.print("<input type=submit value=ON style=width:100px;height:45px onClick=location.href='/on8'>");
client.print(" <input type=submit value=OFF style=width:100px;height:45px onClick=location.href='/?off9'>");
//////Check for button press and switch outputs on or off/////
if(readString.indexOf("on4") >0) //see if ON button was clicked and switch relay on if 4 found
{
digitalWrite(shed_light_relay, HIGH);
client.println(" <font color='green'>--SHED LIGHT ON--</font"); //show status on
}
else if(readString.indexOf("off5") >0)
{
digitalWrite(shed_light_relay, LOW);
client.println(" <font color='red'>--SHED LIGHT OFF--</font"); //show status off
}
else if(digitalRead(shed_light_relay) == LOW) // check the pin for LOW state
{
client.println(" <font color='red'>--SHED LIGHT OFF--</font"); //show status off
}
else
{
client.println(" <font color='green'>--SHED LIGHT ON--</font"); //show status on
}
if(readString.indexOf("on6") >0) //see if ON button was clicked and switch relay on if 6 found
{
digitalWrite(heating_relay, HIGH);
client.println(" <font color='green'>--HEATING ON--</font"); //show status on
}
else if(readString.indexOf("off7") >0)
{
digitalWrite(heating_relay, LOW);
client.println(" <font color='red'>--HEATING OFF--</font"); //show status off
}
else if(digitalRead(heating_relay) == LOW) // check the pin for LOW state
{
client.println(" <font color='red'>--HEATING OFF--</font"); //show status off
}
else
{
client.println(" <font color='green'>--HEATING ON--</font"); //show status on
}
if(readString.indexOf("on8") >0) //see if ON button was clicked and switch relay on if 8 found
{
digitalWrite(shed_lock_relay, HIGH);
client.println(" <font color='green'>--SHED LOCK ON--</font"); //show status on
}
else if(readString.indexOf("off9") >0)
{
digitalWrite(shed_lock_relay, LOW);
client.println(" <font color='red'>--SHED LOCK OFF--</font"); //show status off
}
else if(digitalRead(shed_lock_relay) == LOW) // check the pin for LOW state
{
client.println(" <font color='red'>--SHED LOCK OFF--</font"); //show status off
}
else
{
client.println(" <font color='green'>--SHED LOCK ON--</font"); //show status on
}
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
//clearing string for next read
readString="";
}
}
}
}
}