Advertisement
Guest User

Html Image LabGaragem1

a guest
Nov 14th, 2016
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.70 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. boolean incoming = 0;
  4. int rele1 = 0;
  5. int rele2 = 0;
  6. int rele3 = 0;
  7. int rele4 = 0;
  8. #define pin_rly1 2
  9. #define pin_rly2 3
  10. #define pin_rly3 4
  11. #define pin_rly4 5
  12. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  13. IPAddress ip(10,0,0,188);
  14. EthernetServer server(8087);
  15. void setup()
  16. {
  17. Ethernet.begin(mac, ip);
  18. server.begin();
  19. Serial.begin(9600);
  20. pinMode(pin_rly1, OUTPUT);
  21. digitalWrite(pin_rly1, LOW);
  22. pinMode(pin_rly2, OUTPUT);
  23. digitalWrite(pin_rly2, LOW);
  24. pinMode(pin_rly3, OUTPUT);
  25. digitalWrite(pin_rly3, LOW);
  26. pinMode(pin_rly4, OUTPUT);
  27. digitalWrite(pin_rly4, LOW);
  28. }
  29. void loop()
  30. {
  31. // listen for incoming clients
  32. EthernetClient client = server.available();
  33. if (client)
  34. {
  35. // an http request ends with a blank line
  36. boolean currentLineIsBlank = true;
  37. String str;
  38. while (client.connected())
  39. {
  40. if (client.available())
  41. {
  42. char c = client.read();
  43. str.concat(c);
  44. if(str.endsWith("/1on")) rele1 =1;
  45. else if(str.endsWith("/1off")) rele1 =0;
  46. if(str.endsWith("/2on")) rele2 =1;
  47. else if(str.endsWith("/2off")) rele2 =0;
  48. if(str.endsWith("/3on")) rele3 =1;
  49. else if(str.endsWith("/3off")) rele3 =0;
  50. if(str.endsWith("/4on")) rele4 =1;
  51. else if(str.endsWith("/4off")) rele4 =0;
  52. if (c == '\n' && currentLineIsBlank)
  53. {
  54. client.println("HTTP/1.1 200 OK");
  55. client.println("Content-Type: text/html"); //inicializa o arquivo html
  56. //client.println("Refresh: 1?); // refresh a pagina a cada 1 seg
  57. client.println();
  58.  
  59. client.println("<style> html,body {height: 100%;");
  60. client.println("background: url(http://inceres.com.br/wp-content/uploads/2016/05/as-vantagens-da-tecnologia-no-agronegocio.jpg) no-repeat center center fixed;");
  61. client.println("background-size: cover; } </style>");
  62.  
  63. client.println("<H1><center>Moises WebServer</H1></center><br/>");
  64. //<H1> Tamanho da letra
  65. //<center> Centraliza o texto que estiver na sequência
  66. //<br> Quebr a de linha
  67. client.println("<hr width=50%>"); // TRaço centralizado na pagina
  68. client.println();
  69. client.println("<UL>"); // iniciar lista não numerada
  70. if(rele1 == 1)
  71. {
  72. client.println("<br><LI><font color='blue' size='5'><a href=http://192.168.0.188/1off/><i>Desligar Saida 1</i></a>");
  73. //<LI> Item não numerado
  74. //<a href=endereço pagina/>texto a ser apresentado</a> link para outra pagina
  75. digitalWrite(pin_rly1, HIGH);
  76. }
  77. else if (rele1 ==0)
  78. {
  79. client.println("<br><LI><font color='blue' size='5'><a href=http://192.168.0.188/1on/>LIGAR SAIDA 1</a>");
  80. digitalWrite(pin_rly1, LOW);
  81. }
  82. if(rele2 == 1)
  83. {
  84. client.println("<br><LI><font color='blue' size='5'><a href=http://192.168.0.188/2off/><i>Desligar Saida 2</i></a>");
  85. digitalWrite(pin_rly2, HIGH);
  86. }
  87. else if (rele2 ==0)
  88. {
  89. client.println("<br><LI><font color='blue' size='5'><a href=http://192.168.0.188/2on/>LIGAR SAIDA 2</a>");
  90. digitalWrite(pin_rly2, LOW);
  91. }
  92. if(rele3 == 1)
  93. {
  94. client.println("<br><LI><font color='blue' size='5'><a href=http://192.168.0.188/3off/><i>Desligar Saida 3</i></a>");
  95. digitalWrite(pin_rly3, HIGH);
  96. }
  97. else if (rele3 ==0)
  98. {
  99. client.println("<br><LI><font color='blue' size='5'><a href=http://192.168.0.188/3on/>LIGAR SAIDA 3</a>");
  100. digitalWrite(pin_rly3, LOW);
  101. }
  102. if(rele4 == 1)
  103. {
  104. client.println("<br><LI><font color='blue' size='5'><a href=http://192.168.0.188/4off/><i>Desligar Saida 4</i></a>");
  105. digitalWrite(pin_rly4, HIGH);
  106. }
  107. else if (rele4 ==0)
  108. {
  109. client.println("<br><LI><font color='blue' size='5'><a href=http://192.168.0.188/4on/>LIGAR SAIDA 4</a>");
  110. digitalWrite(pin_rly4, LOW);
  111. }
  112. client.println("</UL>");
  113. break;
  114. }
  115. if (c == '\n')
  116. {
  117. currentLineIsBlank = true;
  118. }
  119. else if (c != '\r')
  120. {
  121. currentLineIsBlank = false;
  122. }
  123. }
  124. }
  125. // give the web browser time to receive the data
  126. delay(1);
  127. // close the connection:
  128. client.stop();
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement