Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #include <ESP8266WebServer.h>
- #include <ESP8266mDNS.h>
- MDNSResponder mdns;
- const char* ssid = "MOTO";
- const char* password = "moises";
- ESP8266WebServer server(80);
- String webSite="";
- int led1 = D3;
- void setup(void){
- webSite +="<title>ESP8266 Demo</title>\n";
- webSite += "<style>body{ background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }</style>\n";
- webSite+="<script>function myFunction() {location.reload();}</script>";
- webSite += "<h2><center>ESP8266 Moises</center></h2>";
- webSite +="<center><p><h1>Luz Da Sala <a href=\"socket1On\"><button><h1>LIGA</h1></button></a> <a href=\"socket1Off\"><button><font color='red'><h1>DESLIGA</h1></font></button></center></h1></a></p>\n";
- // preparing GPIOs
- pinMode(led1, OUTPUT);
- digitalWrite(led1, LOW);
- Serial.begin(115200);
- WiFi.begin(ssid, password);
- Serial.println("");
- // Wait for connection
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.print("Connected to ");
- Serial.println(ssid);
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
- if (mdns.begin("esp8266", WiFi.localIP())) {
- Serial.println("MDNS responder started");
- }
- server.on("/", [](){
- server.send(200, "text/html", webSite);
- });
- server.on("/socket1On", [](){
- server.send(200, "text/html", webSite);
- digitalWrite(led1, HIGH);
- });
- server.on("/socket1Off", [](){
- server.send(200, "text/html", webSite);
- digitalWrite(led1, LOW);
- });
- server.begin();
- Serial.println("HTTP server started");
- }
- void loop(void){
- server.handleClient();
- String sentences="<p>Flame is detected!!!</p>";
- if(WiFi.status() != WL_CONNECTED)
- {
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement