Advertisement
RuiViana

Automation

Mar 31st, 2016
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <SerialRelay.h>
  3. #include <Ethernet_v2.h>
  4. #include <DS1307.h>
  5. #include <String.h>
  6. #include <DHT.h>
  7.  
  8.  
  9. byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x70, 0xbC };
  10. IPAddress ip( 192, 168, 1, 12 );
  11. EthernetServer server(80);
  12. SerialRelay relays(8,9,2); // (data, clock, number of modules)
  13. DS1307 rtc(A4, A5);
  14. #define DHTPIN A1 // pino que estamos conectado
  15. #define DHTTYPE DHT11 // DHT 11
  16. DHT dht(DHTPIN, DHTTYPE);
  17.  
  18. String readString = String(300);
  19.  
  20. String statusSala;
  21. String statusRecepcao;
  22. String statusArquivo;
  23.  
  24. boolean RelaySala = false; // varivel para guardar o estado do rele
  25. boolean RelayRecepcao = false;
  26. boolean RelayArquivo = false;
  27.  
  28. String Display;
  29. String Temp;
  30.  
  31. float h;
  32. float Xpto;
  33. Display += Xpto;
  34.  
  35. void setup() {
  36. Ethernet.begin(mac, ip);
  37. rtc.halt(false);
  38.  
  39. //As linhas abaixo setam a data e hora do modulo
  40. //e podem ser comentada apos a primeira utilizacao
  41. //rtc.setDOW(SATURDAY); //Define o dia da semana
  42. //rtc.setTime(20, 25, 10 ); //Define o horario
  43. //rtc.setDate(26, 03, 2016); //Define o dia, mes e ano
  44.  
  45. //Definicoes do pino SQW/Out
  46. rtc.setSQWRate(SQW_RATE_1);
  47. rtc.enableSQW(true);
  48. }
  49. void loop()
  50. {
  51. h = dht.readHumidity();
  52. Xpto= dht.readTemperature();
  53.  
  54. Display = "C:"; // C: no texto
  55. Display += Xpto; // valor da temperatura no texto
  56. Display += " H:"; // H: no texto
  57. Display += h; // valor da umidade no texto
  58.  
  59. String str=rtc.getTimeStr();
  60. String str2="17:30:00";
  61. if (str==str2){
  62. relays.SetRelay(1, SERIAL_RELAY_OFF, 1);
  63. relays.SetRelay(2, SERIAL_RELAY_OFF, 1);
  64. relays.SetRelay(3, SERIAL_RELAY_OFF, 1);
  65. relays.SetRelay(4, SERIAL_RELAY_OFF, 1);
  66. relays.SetRelay(1, SERIAL_RELAY_OFF, 2);
  67. relays.SetRelay(2, SERIAL_RELAY_OFF, 2);
  68. RelaySala = false;
  69. RelayRecepcao = false;
  70. RelayArquivo = false;
  71. statusSala="Desligado";
  72. statusRecepcao="Desligado";
  73. statusArquivo="Desligado";
  74.  
  75. }
  76. EthernetClient client = server.available();
  77. if(client)
  78. {
  79. while(client.connected())
  80. {
  81. if(client.available());
  82. {
  83. char c = client.read();
  84. if(readString.length() < 300)
  85. {
  86. readString += (c);
  87. }
  88. if(c == '\n')
  89. {
  90. if(readString.indexOf("Sala") >=0) {
  91. if(RelaySala) { // se o rele estiver ativado (true)
  92. relays.SetRelay(1, SERIAL_RELAY_OFF, 1); // desliga o rele
  93. delay(1000);
  94. relays.SetRelay(2, SERIAL_RELAY_OFF, 1);
  95. RelaySala = false; // define como false para sinalizar que esta desligado
  96. } else {
  97. relays.SetRelay(1, SERIAL_RELAY_ON, 1); // senao liga o rele
  98. delay(1000);
  99. relays.SetRelay(2, SERIAL_RELAY_ON, 1);
  100. RelaySala = true; // define como true para sinalizar que ele esta ligado
  101. }}else if(readString.indexOf("Recepcao") >=0) {
  102. if(RelayRecepcao) { // se o rele estiver ativado (true)
  103. relays.SetRelay(3, SERIAL_RELAY_OFF, 1); // desliga o rele
  104. delay(1000);
  105. relays.SetRelay(4, SERIAL_RELAY_OFF, 1);
  106. RelayRecepcao = false; // define como false para sinalizar que esta desligado
  107. } else {
  108. relays.SetRelay(3, SERIAL_RELAY_ON, 1); // senao liga o rele
  109. delay(1000);
  110. relays.SetRelay(4, SERIAL_RELAY_ON, 1);
  111. RelayRecepcao = true; // define como true para sinalizar que ele esta ligado
  112. }}else if(readString.indexOf("Arquivo") >=0) {
  113. if(RelayArquivo) { // se o rele estiver ativado (true)
  114. relays.SetRelay(1, SERIAL_RELAY_OFF, 2); // desliga o rele
  115. delay(1000);
  116. relays.SetRelay(2, SERIAL_RELAY_OFF, 2);
  117. RelayArquivo = false; // define como false para sinalizar que esta desligado
  118. } else {
  119. relays.SetRelay(1, SERIAL_RELAY_ON, 2); // senao liga o rele
  120. delay(1000);
  121. relays.SetRelay(2, SERIAL_RELAY_ON, 2);
  122. RelayArquivo = true; // define como true para sinalizar que ele esta ligado
  123. }
  124. }
  125. client.println("HTTP/1.1 200 OK");
  126. client.println("Content-Type: text/html");
  127. client.println("Connnection: close");
  128. client.println();
  129. client.println("<!DOCTYPE HTML>");
  130. client.println("<html>");
  131. client.println("<head>");
  132. client.println("<title>Automacao Residencial V 1.0 By EduTel</title>");
  133. client.println("<meta name=\"viewport\" content=\"width=320\">");
  134. client.println("<meta name=\"viewport\" content=\"width=device-width\">");
  135. client.println("<meta charset=\"utf-8\">");
  136. client.println("<meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no\">");
  137. client.println("<meta http-equiv=\"refresh\" content=\"1; URL=http://192.168.1.12\">");
  138. client.println("</head>");
  139. client.println("<body>");
  140. client.println("<center>");
  141. client.println("<font size=\"5\" face=\"verdana\" color=\"Orange\">EduTel</font>");
  142. client.println("<font size=\"3\" face=\"verdana\" color=\"red\"> & </font>");
  143. client.println("<font size=\"5\" face=\"verdana\" color=\"Orange\">EduCel</font><br />");
  144. client.println("<font size=\"5\" face=\"verdana\" color=\"Orange\">Automacao Residencial V 1.0</font><br />");
  145. client.println("<font size=\"5\" face=\"verdana\" color=\"black\">Hora:"+str+"</font><br />");
  146. client.println("<font size=\"5\" face=\"verdana\" color=\"black\">Humidade:"+humidade+"</font><br />");
  147. client.println("<font size=\"5\" face=\"verdana\" color=\"black\">Temperatura:"+temp+"*C""</font><br />");
  148. if(RelaySala == false){
  149. statusSala="Desligado";
  150. }else{
  151. statusSala="Ligado";
  152. }
  153. client.println("<form action=\"Sala\" method=\"get\">");
  154. client.println("<button type=submit style=\"width:200px;\">Lampadas Sala -"+statusSala+"</button>");
  155. client.println("</form> <br />");
  156. if(RelayRecepcao == false){
  157. statusRecepcao="Desligado";
  158. }else{
  159. statusRecepcao="Ligado";
  160. }
  161. client.println("<form action=\"Recepcao\" method=\"get\">");
  162. client.println("<button type=submit style=\"width:200px;\">Lampadas Recepcao -"+statusRecepcao+"</button>");
  163. client.println("</form> <br />");
  164. if(RelayArquivo == false){
  165. statusArquivo="Desligado";
  166. }else{
  167. statusArquivo="Ligado";
  168. }
  169. client.println("<form action=\"Arquivo\" method=\"get\">");
  170. client.println("<button type=submit style=\"width:200px;\">Lampadas Arquivo -"+statusArquivo+"</button>");
  171. client.println("</form> <br />");
  172. client.println("</center>");
  173. client.println("</body>");
  174. client.println("</html>");
  175. readString="";
  176. client.stop();
  177. }
  178. }
  179. }
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement