/* D v d B */ #include #include // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: byte mac[] = { 0xAE, 0xFE, 0xDE, 0xEF, 0xFD, 0xFD }; byte gateway[] = { 192, 168, 2, 254 }; // <------- PUT YOUR ROUTERS IP Address to which your shield is connected Here byte subnet[] = { 255, 255, 255, 0 }; // <------- It will be as it is in most of the cases IPAddress ip(192,168,2,10); // Initialize the Ethernet server library // with the IP address and port you want to use // (port 80 is default for HTTP): EthernetServer server(80); #define RELAY_CH1 2 #define RELAY_CH2 3 #define RELAY_CH3 4 #define RELAY_CH4 5 #define RELAY_CH5 6 #define RELAY_CH6 7 #define RELAY_CH7 8 #define RELAY_CH8 9 String readString; void setup() { pinMode(RELAY_CH1, OUTPUT); digitalWrite(RELAY_CH1, HIGH); // switch on LED1 pinMode(RELAY_CH2, OUTPUT); digitalWrite(RELAY_CH2, HIGH); // switch on LED2 pinMode(RELAY_CH3, OUTPUT); digitalWrite(RELAY_CH3, HIGH); // switch on LED3 pinMode(RELAY_CH4, OUTPUT); digitalWrite(RELAY_CH4, HIGH); // switch on LED4 pinMode(RELAY_CH5, OUTPUT); digitalWrite(RELAY_CH5, HIGH); // switch on LED5 pinMode(RELAY_CH6, OUTPUT); digitalWrite(RELAY_CH6, HIGH); // switch on LED6 pinMode(RELAY_CH7, OUTPUT); digitalWrite(RELAY_CH7, HIGH); // switch on LED7 pinMode(RELAY_CH8, OUTPUT); digitalWrite(RELAY_CH8, HIGH); // switch on LED8 // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } // start the Ethernet connection and the server: Ethernet.begin(mac, ip); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); } void loop() { // listen for incoming clients EthernetClient client = server.available(); if (client) { Serial.println("new client"); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); if (readString.length() < 100) { //store characters to string readString += c; //Serial.print(c); } Serial.write(c); // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); //client.println("Connection: close"); // the connection will be closed after completion of the response //client.println("Refresh: 20"); // refresh the page automatically every 5 sec client.println(); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.println("" ); client.println(""); client.println(""); //client.println("
"); //client.println("
"); client.println("

"); //client.println("
"); //client.println("
"); client.print("

"); //client.println("
"); //client.println("
"); // Relay Status Display //client.println("
"); //client.println(""); //client.println(""); //if (digitalRead(RELAY_CH1)) { //client.print(""); } //else { //client.print(""); } //if (digitalRead(RELAY_CH2)) { //client.print(""); } //else { //client.print(""); } //if (digitalRead(RELAY_CH3)) { //client.print(""); } //else { //client.print(""); } //if (digitalRead(RELAY_CH4)) { //client.print(""); } //else { //client.print(""); } //if (digitalRead(RELAY_CH5)) { //client.print(""); } //else { //client.print(""); } //if (digitalRead(RELAY_CH6)) { //client.print(""); } //else { //client.print(""); } //if (digitalRead(RELAY_CH7)) { //client.print(""); } //else { //client.print(""); } //if (digitalRead(RELAY_CH8)) { //client.print(""); } //else { //client.print(""); } //client.println(""); //client.println("

Lamp 1.

ON

Lamp 1.

OFF

Lamp 2.

ON

Lamp 2.

OFF

Lamp 3.

ON

Lamp 3.

OFF

Lamp 4.

ON

Lamp 4.

OFF

Lamp 5.

ON

Lamp 5.

OFF

Lamp 6.

ON

Lamp 6.

OFF

Lamp 7.

ON

Lamp 7.

OFF

Lamp 8.

ON

Lamp 8.

OFF

"); //client.println("
"); //client.println("
"); //End relay status display /* Relay Control Code */ client.println(" "); client.println("
"); client.println("
"); client.println(" "); client.println("
"); client.println("
"); client.println(" "); client.println("
"); client.println("
"); client.println(" "); client.println("
"); client.println("
"); client.println(" "); client.println("
"); client.println("
"); client.println(" "); client.println("
"); client.println("
"); client.println(" "); client.println("
"); client.println("
"); client.println(" "); client.println("
"); client.println("
"); // control arduino pin via ethernet Start // if(readString.indexOf("?relay1off") >0)//checks for on { digitalWrite(RELAY_CH1, HIGH); // set pin 4 high //Serial.println("Led On"); client.println(""); //client.println("Light 1 Is On"); client.println("
"); } else{ if(readString.indexOf("?relay1on") >0)//checks for off { digitalWrite(RELAY_CH1, LOW); // set pin 4 low //Serial.println("Led Off"); client.println(""); //client.println("Light 1 Is Off"); client.println("
"); } } if(readString.indexOf("?relay2off") >0)//checks for on { digitalWrite(RELAY_CH2, HIGH); // set pin 4 high //Serial.println("Led On"); client.println(""); //client.println("Light 1 Is On"); client.println("
"); } else{ if(readString.indexOf("?relay2on") >0)//checks for off { digitalWrite(RELAY_CH2, LOW); // set pin 4 low //Serial.println("Led Off"); client.println(""); //client.println("Light 1 Is Off"); client.println("
"); } } if(readString.indexOf("?relay3off") >0)//checks for on { digitalWrite(RELAY_CH3, HIGH); // set pin 4 high //Serial.println("Led On"); client.println(""); //client.println("Light 1 Is On"); client.println("
"); } else{ if(readString.indexOf("?relay3on") >0)//checks for off { digitalWrite(RELAY_CH3, LOW); // set pin 4 low //Serial.println("Led Off"); client.println(""); //client.println("Light 1 Is Off"); client.println("
"); } } if(readString.indexOf("?relay4off") >0)//checks for on { digitalWrite(RELAY_CH4, HIGH); // set pin 4 high //Serial.println("Led On"); client.println(""); //client.println("Light 1 Is On"); client.println("
"); } else{ if(readString.indexOf("?relay4on") >0)//checks for off { digitalWrite(RELAY_CH4, LOW); // set pin 4 low //Serial.println("Led Off"); client.println(""); //client.println("Light 1 Is Off"); client.println("
"); } } if(readString.indexOf("?relay5off") >0)//checks for on { digitalWrite(RELAY_CH5, HIGH); // set pin 4 high //Serial.println("Led On"); client.println(""); //client.println("Light 1 Is On"); client.println("
"); } else{ if(readString.indexOf("?relay5on") >0)//checks for off { digitalWrite(RELAY_CH5, LOW); // set pin 4 low //Serial.println("Led Off"); client.println(""); //client.println("Light 1 Is Off"); client.println("
"); } } if(readString.indexOf("?relay6off") >0)//checks for on { digitalWrite(RELAY_CH6, HIGH); // set pin 4 high //Serial.println("Led On"); client.println(""); //client.println("Light 1 Is On"); client.println("
"); } else{ if(readString.indexOf("?relay6on") >0)//checks for off { digitalWrite(RELAY_CH6, LOW); // set pin 4 low //Serial.println("Led Off"); client.println(""); //client.println("Light 1 Is Off"); client.println("
"); } } if(readString.indexOf("?relay7off") >0)//checks for on { digitalWrite(RELAY_CH7, HIGH); // set pin 4 high //Serial.println("Led On"); client.println(""); //client.println("Light 1 Is On"); client.println("
"); } else{ if(readString.indexOf("?relay7on") >0)//checks for off { digitalWrite(RELAY_CH7, LOW); // set pin 4 low //Serial.println("Led Off"); client.println(""); //client.println("Light 1 Is Off"); client.println("
"); } } if(readString.indexOf("?relay8off") >0)//checks for on { digitalWrite(RELAY_CH8, HIGH); // set pin 4 high //Serial.println("Led On"); client.println(""); //client.println("Light 1 Is On"); client.println("
"); } else{ if(readString.indexOf("?relay8on") >0)//checks for off { digitalWrite(RELAY_CH8, LOW); // set pin 4 low //Serial.println("Led Off"); client.println(""); //client.println("Light 1 Is Off"); client.println("
"); } } // INPUT // output the value of each analog input pin //for (int analogChannel = 0; analogChannel < 6; analogChannel++) { // int sensorReading = analogRead(analogChannel); // client.print("analog input "); // client.print(analogChannel); // client.print(" is "); // client.print(sensorReading); // client.println("
"); //} client.println("

By

Danny van den Brande

"); readString=""; client.println(""); client.println(""); break; }// if ( c == \n ) if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data delay(1); //client.println("" ); // close the connection: client.stop(); Serial.println("client disonnected"); }//if(Client) }//Loop