How to Control LED On-Off Through Wifi using ESP8266

Sdílet
Vložit
  • čas přidán 12. 09. 2024
  • Controlling LED through Wifi using ESP8266 and Android Phone
    • How to Control LED On-...
    ESP8266 Wifi Relay Module
    • ESP8266 Wifi Relay Mod...
    ESP8266 Wifi Control LED On-Off
    • ESP8266 as a Wifi Web ...
    ESP8266 Wifi Controlling LED On-Off
    • WIFI Hotspot | NodeMCU...
    ESP8266 Wifi Scan
    • WIFI Scan ESP8266 Node... ...

Komentáře • 2

  • @HabiburRahman-wk1up
    @HabiburRahman-wk1up Před 3 měsíci

    Bro can you provide the code please?

    • @tagalogelectronics6615
      @tagalogelectronics6615  Před 3 měsíci

      Ok sir this is the CODE.....
      #include
      #include
      /* Put your SSID & Password */
      const char* ssid = "bototoy";
      const char* password = "12345789";
      ESP8266WebServer server(80);
      bool LEDstatus = LOW;
      void setup() {
      Serial.begin(9600);
      pinMode(D4, OUTPUT);
      WiFi.softAP(ssid, password);
      IPAddress myIP = WiFi.softAPIP();
      Serial.print("Access Point IP:");
      Serial.println(myIP);

      server.on("/", handle_OnConnect);
      server.on("/ledon", handle_ledon);
      server.on("/ledoff", handle_ledoff);
      server.onNotFound(handle_NotFound);

      server.begin();
      //Serial.println("HTTP Server Started");
      }
      void loop() {
      server.handleClient();

      if(LEDstatus)
      {digitalWrite(D4, HIGH);}
      else
      {digitalWrite(D4, LOW);}
      }
      void handle_OnConnect() {
      LEDstatus = LOW;
      Serial.println("LED: OFF");
      server.send(200, "text/html", updateWebpage(LEDstatus));
      }
      void handle_ledon() {
      LEDstatus = HIGH;
      Serial.println("LED: ON");
      server.send(200, "text/html", updateWebpage(LEDstatus));
      }
      void handle_ledoff() {
      LEDstatus = LOW;
      Serial.println("LED: OFF");
      server.send(200, "text/html", updateWebpage(LEDstatus));
      }
      void handle_NotFound(){
      server.send(404, "text/plain", "Not found");
      }
      String updateWebpage(uint8_t LEDstatus){
      String ptr = "
      ";
      ptr +="
      ";
      ptr +="LED Control
      ";
      ptr +="html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}
      ";
      ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3 {color: #444444;margin-bottom: 50px;}
      ";
      ptr +=".button {display: block;width: 80px;background-color: #1abc9c;border: none;color: white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px auto 35px;cursor: pointer;border-radius: 4px;}
      ";
      ptr +=".button-on {background-color: #3498db;}
      ";
      ptr +=".button-on:active {background-color: #3498db;}
      ";
      ptr +=".button-off {background-color: #34495e;}
      ";
      ptr +=".button-off:active {background-color: #2c3e50;}
      ";
      ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}
      ";
      ptr +="
      ";
      ptr +="
      ";
      ptr +="
      ";
      ptr +="ESP8266 Web Server
      ";
      ptr +="Using Access Point(AP) Mode
      ";

      if(LEDstatus){
      ptr +="BLUE LED: ONOFF
      ";
      }else{
      ptr +="BLUE LED: OFFON
      ";
      }
      ptr +="
      ";
      ptr +="
      ";
      return ptr;
      }