document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. #include <Wire.h>
  4. #include <LiquidCrystal_I2C.h>
  5. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
  6.  
  7. boolean statop1 = false;
  8. boolean statop2 = false;
  9. boolean statop3 = false;
  10. boolean statop4 = false;
  11.  
  12. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
  13. byte ip[] = { 192, 168, 0, 50 }; // ip in lan
  14. byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
  15. byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
  16. EthernetServer server(80); //server port
  17.  
  18. String readString;
  19.  
  20. //////////////////////
  21.  
  22. void setup(){
  23.  
  24. pinMode(7, OUTPUT); //pin selected to control
  25. pinMode(6, OUTPUT); //pin selected to control
  26. pinMode(5, OUTPUT); //pin selected to control
  27. pinMode(4, OUTPUT); //pin selected to control
  28. //start Ethernet
  29. Ethernet.begin(mac, ip, gateway, subnet);
  30. server.begin();
  31. Serial.begin(9600);
  32. Serial.println("Domotic Server test 1.0"); // so I can keep track of what is loaded
  33. lcd.begin(16,2);
  34.  
  35.  
  36. for(int i = 0; i< 3; i++)
  37. {
  38. lcd.backlight();
  39. delay(250);
  40. lcd.noBacklight();
  41. delay(250);
  42. }
  43. lcd.backlight();
  44. lcd.setCursor(0,0);
  45. lcd.print("CM RELAY V1.0");
  46. delay(1000);
  47. lcd.setCursor(0,1);
  48. lcd.print("TEST OK");
  49. delay(5000);
  50. lcd.clear();
  51. lcd.setCursor(0,0);
  52. lcd.print("LAN");
  53. lcd.setCursor(0,1);
  54. lcd.print("192.168.0.50");
  55.  
  56. }
  57.  
  58. void loop(){
  59. // Create a client connection
  60. EthernetClient client = server.available();
  61. if (client) {
  62. while (client.connected()) {
  63. if (client.available()) {
  64. char c = client.read();
  65.  
  66. //read char by char HTTP request
  67. if (readString.length() < 100) {
  68.  
  69. //store characters to string
  70. readString += c;
  71. //Serial.print(c);
  72. }
  73.  
  74. //if HTTP request has ended
  75. if (c == '\\n') {
  76.  
  77. ///////////////
  78. Serial.println(readString); //print to serial monitor for debuging
  79.  
  80. client.println("HTTP/1.1 200 OK"); //send new page
  81. client.println("Content-Type: text/html");
  82. client.println();
  83.  
  84. 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>");
  85.  
  86. delay(1);
  87. //stopping client
  88. client.stop();
  89.  
  90. ///////////////////// control arduino pin
  91. if(readString.indexOf("?light1on") >0)//checks for on
  92. {
  93. statop1 = true;
  94. }
  95. if(readString.indexOf("?light1off") >0)//checks for off
  96. {
  97. statop1 = false;
  98. }
  99. if(readString.indexOf("?light2on") >0)//checks for on
  100. {
  101. statop2 = true;
  102. }
  103. if(readString.indexOf("?light2off") >0)//checks for off
  104. {
  105. statop2 = false;
  106. }
  107. if(readString.indexOf("?light3on") >0)//checks for on
  108. {
  109. statop3 = true;
  110. }
  111. if(readString.indexOf("?light3off") >0)//checks for off
  112. {
  113. statop3 = false;
  114. }
  115. if(readString.indexOf("?light4on") >0)//checks for on
  116. {
  117. statop4 = true;
  118. }
  119. if(readString.indexOf("?light4off") >0)//checks for off
  120. {
  121. statop4 = false;
  122. }
  123.  
  124.  
  125. if(statop1 == true)
  126. {
  127. digitalWrite(7, LOW);
  128. }
  129. if(statop1 == false)
  130. {
  131. digitalWrite(7, HIGH);
  132. }
  133. if(statop2 == true)
  134. {
  135. digitalWrite(6, LOW);
  136. }
  137. if(statop2 == false)
  138. {
  139. digitalWrite(6, HIGH);
  140. }
  141. if(statop3 == true)
  142. {
  143. digitalWrite(5, LOW);
  144. }
  145. if(statop3 == false)
  146. {
  147. digitalWrite(5, HIGH);
  148. }
  149. if(statop4 == true)
  150. {
  151. digitalWrite(4, LOW);
  152. }
  153. if(statop4 == false)
  154. {
  155. digitalWrite(4, HIGH);
  156. }
  157. //clearing string for next read
  158. readString="";
  159.  
  160.  
  161.  
  162. }
  163. }
  164. }
  165. }
  166. }
');