Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
- boolean statop1 = false;
- boolean statop2 = false;
- boolean statop3 = false;
- boolean statop4 = false;
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
- byte ip[] = { 192, 168, 0, 50 }; // ip in lan
- byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
- byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
- EthernetServer server(80); //server port
- String readString;
- //////////////////////
- void setup(){
- pinMode(7, OUTPUT); //pin selected to control
- pinMode(6, OUTPUT); //pin selected to control
- pinMode(5, OUTPUT); //pin selected to control
- pinMode(4, OUTPUT); //pin selected to control
- //start Ethernet
- Ethernet.begin(mac, ip, gateway, subnet);
- server.begin();
- Serial.begin(9600);
- Serial.println("Domotic Server test 1.0"); // so I can keep track of what is loaded
- lcd.begin(16,2);
- for(int i = 0; i< 3; i++)
- {
- lcd.backlight();
- delay(250);
- lcd.noBacklight();
- delay(250);
- }
- lcd.backlight();
- lcd.setCursor(0,0);
- lcd.print("CM RELAY V1.0");
- delay(1000);
- lcd.setCursor(0,1);
- lcd.print("TEST OK");
- delay(5000);
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("LAN");
- lcd.setCursor(0,1);
- lcd.print("192.168.0.50");
- }
- 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("<!DOCTYPE html><html><head><meta name='apple-mobile-web-app-capable' content='yes'><meta name='apple-mobile-web-app-status-bar-style' content='black-translucent'><link rel='stylesheet' type='text/css' href='http://homeautocss.net84.net/a.css'><TITLE>rele' tester computermuseo</TITLE></HEAD><BODY><H1>relè tester computermuseo</H1><hr><br><ul><li><p align=\"left\">rele 1:<a href=\"/?light1on\">accendi</a><a href=\"/?light1off\">spegni</a></li></p><br><br><li><p align=\"left\">rele 2:<a href=\"/?light2on\">accendi</a><a href=\"/?light2off\">spegni</a></li></p><br><br><li><p align=\"left\">rele 3:<a href=\"/?light3on\">accendi</a><a href=\"/?light3off\">spegni</a></li></p><br><br><li><p align=\"left\">rele 4:<a href=\"/?light4on\">accendi</a><a href=\"/?light4off\">spegni</a></li></p><br><br></ul></BODY></HTML>");
- delay(1);
- //stopping client
- client.stop();
- ///////////////////// control arduino pin
- if(readString.indexOf("?light1on") >0)//checks for on
- {
- statop1 = true;
- }
- if(readString.indexOf("?light1off") >0)//checks for off
- {
- statop1 = false;
- }
- if(readString.indexOf("?light2on") >0)//checks for on
- {
- statop2 = true;
- }
- if(readString.indexOf("?light2off") >0)//checks for off
- {
- statop2 = false;
- }
- if(readString.indexOf("?light3on") >0)//checks for on
- {
- statop3 = true;
- }
- if(readString.indexOf("?light3off") >0)//checks for off
- {
- statop3 = false;
- }
- if(readString.indexOf("?light4on") >0)//checks for on
- {
- statop4 = true;
- }
- if(readString.indexOf("?light4off") >0)//checks for off
- {
- statop4 = false;
- }
- if(statop1 == true)
- {
- digitalWrite(7, LOW);
- }
- if(statop1 == false)
- {
- digitalWrite(7, HIGH);
- }
- if(statop2 == true)
- {
- digitalWrite(6, LOW);
- }
- if(statop2 == false)
- {
- digitalWrite(6, HIGH);
- }
- if(statop3 == true)
- {
- digitalWrite(5, LOW);
- }
- if(statop3 == false)
- {
- digitalWrite(5, HIGH);
- }
- if(statop4 == true)
- {
- digitalWrite(4, LOW);
- }
- if(statop4 == false)
- {
- digitalWrite(4, HIGH);
- }
- //clearing string for next read
- readString="";
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement