Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://youtu.be/asCd8rSppe0//
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #include <ESP8266WebServer.h>
- #include <ESP8266mDNS.h>
- #include <WiFiManager.h>
- #include <DNSServer.h>
- ESP8266WebServer server(81);
- DNSServer dnsServer;
- int state =0;
- const int output1 = 0;
- const int btn = 2;
- //int btn;
- boolean Relay1 = false;
- WiFiManager wifiManager;
- //void AP_staticIP(void);
- ///void toggle(void);
- void client_staticIP(void);
- void handleRoot() {
- String cmd;
- cmd += "<!DOCTYPE HTML>\r\n";
- cmd += "<html>\r\n";
- cmd += "<header><title>Home Automation</title><center><h1>\"Home Automation\"</h1></center></header>";
- cmd += "<style> body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }</style>";
- cmd += "<head>";
- cmd += "<meta http-equiv='refresh' content='5'/>";
- cmd += "</head>";
- if(Relay1 ==1 ){
- cmd +=("<br/><center>Relay : ON");
- }
- else{
- cmd +=("<br/><center>Relay : OFF");
- }
- cmd += "<html>\r\n";
- server.send(200, "text/html", cmd);
- }
- void handleNotFound(){
- //digitalWrite(led, 1);
- String message = "File Not Found\n\n";
- message += "URI: ";
- message += server.uri();
- message += "\nMethod: ";
- message += (server.method() == HTTP_GET)?"GET":"POST";
- message += "\nArguments: ";
- message += server.args();
- message += "\n";
- for (uint8_t i=0; i<server.args(); i++){
- message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
- }
- server.send(404, "text/plain", message);
- //digitalWrite(led, 0);
- }
- /*
- void AP_staticIP(){
- wifiManager.setAPStaticIPConfig(IPAddress(10,1,1,10), IPAddress(10,1,1,1), IPAddress(255,255,255,0));
- wifiManager.autoConnect("Home Automation", "password");
- }
- */
- void client_staticIP(){
- wifiManager.setSTAStaticIPConfig(IPAddress(192,168,1,175), IPAddress(192,168,1,1), IPAddress(255,255,255,0));
- wifiManager.autoConnect("Home_Automation","password");
- }
- /*
- void client_staticIP(){
- wifiManager.setSTAStaticIPConfig(IPAddress(10,0,0,150), IPAddress(10,0,0,1), IPAddress(255,255,255,0));
- wifiManager.autoConnect("Home_Automation","password");
- }
- */
- void toogle(){
- digitalWrite(output1,(state)? HIGH:LOW);
- //digitalWrite(output1,(!output1));
- state=!state;
- delay(500);
- }
- void setup(void){
- client_staticIP();
- //AP_staticIP();
- pinMode(output1, OUTPUT);
- digitalWrite(output1, LOW);
- pinMode(btn, INPUT);
- //pinMode(output2, OUTPUT);
- //digitalWrite(output2, LOW);
- server.on("/", handleRoot);
- server.on("/RL1=1", [](){
- server.send(200, "text/plain","↑");
- digitalWrite(output1, HIGH);
- Relay1 = true;
- });
- server.on("/RL1=0", [](){
- server.send(200, "text/plain","↓");
- digitalWrite(output1, LOW);
- Relay1 = false;
- });
- server.onNotFound(handleNotFound);
- server.begin();
- Serial.println("HTTP server started");
- }//end setup
- void loop(void){
- if ((!digitalRead(btn))) {
- toogle();
- }
- server.handleClient();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement