Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1.  
  2. #include <ESP8266WiFi.h>
  3. #include <WiFiClient.h>
  4. #include <ESP8266WebServer.h>
  5. #include <ESP8266mDNS.h>
  6.  
  7. MDNSResponder mdns;
  8.  
  9. const char* ssid = "MOTO";
  10. const char* password = "moises";
  11.  
  12. ESP8266WebServer server(80);
  13. String webSite="";
  14.  
  15.  
  16. int led1 = D3;
  17.  
  18.  
  19.  
  20.  
  21. void setup(void){
  22.  
  23. webSite +="<title>ESP8266 Demo</title>\n";
  24. webSite += "<style>body{ background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }</style>\n";
  25.  
  26.  
  27.  
  28.  
  29. webSite+="<script>function myFunction() {location.reload();}</script>";
  30. webSite += "<h2><center>ESP8266 Moises</center></h2>";
  31.  
  32. webSite +="<center><p><h1>Luz Da Sala&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"socket1On\"><button><h1>LIGA</h1></button></a>&nbsp;&nbsp;<a href=\"socket1Off\"><button><font color='red'><h1>DESLIGA</h1></font></button></center></h1></a></p>\n";
  33.  
  34.  
  35. // preparing GPIOs
  36. pinMode(led1, OUTPUT);
  37. digitalWrite(led1, LOW);
  38.  
  39.  
  40. Serial.begin(115200);
  41. WiFi.begin(ssid, password);
  42. Serial.println("");
  43. // Wait for connection
  44. while (WiFi.status() != WL_CONNECTED) {
  45. delay(500);
  46. Serial.print(".");
  47. }
  48.  
  49. Serial.println("");
  50. Serial.print("Connected to ");
  51. Serial.println(ssid);
  52. Serial.print("IP address: ");
  53. Serial.println(WiFi.localIP());
  54.  
  55. if (mdns.begin("esp8266", WiFi.localIP())) {
  56. Serial.println("MDNS responder started");
  57. }
  58. server.on("/", [](){
  59. server.send(200, "text/html", webSite);
  60. });
  61. server.on("/socket1On", [](){
  62. server.send(200, "text/html", webSite);
  63. digitalWrite(led1, HIGH);
  64. });
  65. server.on("/socket1Off", [](){
  66. server.send(200, "text/html", webSite);
  67. digitalWrite(led1, LOW);
  68. });
  69.  
  70.  
  71. server.begin();
  72. Serial.println("HTTP server started");
  73. }
  74.  
  75. void loop(void){
  76. server.handleClient();
  77. String sentences="<p>Flame is detected!!!</p>";
  78. if(WiFi.status() != WL_CONNECTED)
  79. {
  80.  
  81.  
  82. while (WiFi.status() != WL_CONNECTED) {
  83. delay(500);
  84. Serial.print(".");
  85. }
  86.  
  87. }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement