Untitled
unknown
plain_text
6 days ago
6.4 kB
2
Indexable
//15 APRIL 2025 ESP JADI STATION #include <ESP8266WiFi.h> #include <ESP8266WebServer.h> /*Put your SSID & Password*/ char ssid[] = "parah"; // Enter SSID here char password[] = "Rudisalim"; //Enter Password here ESP8266WebServer server(80); uint8_t LED1pin = D7; bool LED1status = LOW; uint8_t LED2pin = D6; bool LED2status = LOW; uint8_t LED3pin = D1; bool LED3status = LOW; void setup() { Serial.begin(115200); delay(100); pinMode(LED1pin, OUTPUT); pinMode(LED2pin, OUTPUT); pinMode(LED3pin, OUTPUT); Serial.println("Connecting to "); Serial.println(ssid); //connect to your local wi-fi network WiFi.begin(ssid, password); //check wi-fi is connected to wi-fi network while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected..!"); Serial.print("Got IP: "); Serial.println(WiFi.localIP()); server.on("/", handle_OnConnect); server.on("/led1on", handle_led1on); server.on("/led1off", handle_led1off); server.on("/led2on", handle_led2on); server.on("/led2off", handle_led2off); server.on("/led3on", handle_led3on); server.on("/led3off", handle_led3off); server.onNotFound(handle_NotFound); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); if(LED1status) {digitalWrite(LED1pin, HIGH);} else {digitalWrite(LED1pin, LOW);} if(LED2status) {digitalWrite(LED2pin, HIGH);} else {digitalWrite(LED2pin, LOW);} if(LED3status) {digitalWrite(LED3pin, HIGH);} else {digitalWrite(LED3pin, LOW);} } void handle_OnConnect() { LED1status = LOW; LED2status = LOW; LED3status = LOW; Serial.println("GPIO7 Status: OFF | GPIO6 Status: OFF | D1: OFF" ); server.send(200, "text/html", SendHTML(LED1status,LED2status,LED3status)); } void handle_led1on() { LED1status = HIGH; Serial.println("GPIO7 Status: ON"); server.send(200, "text/html", SendHTML(true, LED2status, LED3status)); } void handle_led1off() { LED1status = LOW; Serial.println("GPIO7 Status: OFF"); server.send(200, "text/html", SendHTML(false, LED2status, LED3status)); } void handle_led2on() { LED2status = HIGH; Serial.println("GPIO6 Status: ON"); server.send(200, "text/html", SendHTML(LED1status, true, LED3status)); } void handle_led2off() { LED2status = LOW; Serial.println("GPIO6 Status: OFF"); server.send(200, "text/html", SendHTML(LED1status, false, LED3status)); } void handle_led3on() { LED3status = HIGH; Serial.println("D1 Status: ON"); server.send(200, "text/html", SendHTML(LED1status, LED2status, true)); } void handle_led3off() { LED3status = LOW; Serial.println("D1 Status: OFF"); server.send(200, "text/html", SendHTML(LED1status, LED2status, false)); } void handle_NotFound(){ server.send(404, "text/plain", "Not found"); } String SendHTML(uint8_t led1stat,uint8_t led2stat, uint8_t led3stat){ String ptr = "<!DOCTYPE html> <html>\n"; ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n"; ptr +="<title>LED Control</title>\n"; ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n"; ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3 {color: #444444;margin-bottom: 50px;}\n"; 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;}\n"; ptr +=".button-on {background-color: #1abc9c;}\n"; ptr +=".button-on:active {background-color: #16a085;}\n"; ptr +=".button-off {background-color: #34495e;}\n"; ptr +=".button-off:active {background-color: #2c3e50;}\n"; ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}\n"; ptr +="</style>\n"; ptr +="</head>\n"; ptr +="<body>\n"; ptr +="<h1>ESP8266 Web Server</h1>\n"; ptr +="<h3>Using Station(STA) Mode</h3>\n"; if(led1stat) {ptr +="<p>LED1 Status: ON</p><a class=\"button button-off\" href=\"/led1off\">OFF</a>\n";} else {ptr +="<p>LED1 Status: OFF</p><a class=\"button button-on\" href=\"/led1on\">ON</a>\n";} if(led2stat) {ptr +="<p>LED2 Status: ON</p><a class=\"button button-off\" href=\"/led2off\">OFF</a>\n";} else {ptr +="<p>LED2 Status: OFF</p><a class=\"button button-on\" href=\"/led2on\">ON</a>\n";} if(led3stat) {ptr +="<p>LED3 Status: ON</p><a class=\"button button-off\" href=\"/led3off\">OFF</a>\n";} else {ptr +="<p>LED3 Status: OFF</p><a class=\"button button-on\" href=\"/led3on\">ON</a>\n";} ptr +="</body>\n"; ptr +="</html>\n"; return ptr; } //15 APRIL 2025 ESP JADI ACCSES POINT #define BLYNK_TEMPLATE_ID "TMPL6DGgEh8ZF" #define BLYNK_TEMPLATE_NAME "PELATIHAN BBPVP" #define BLYNK_AUTH_TOKEN "ikKXKjXRlhdyqkep82-eXIXLJ0oOUo1G" #include <BlynkRpcClient.h> #include <Blynk.h> #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> char ssid[] = "parah"; char pass [] = "Rudisalim"; char auth[] = "ikKXKjXRlhdyqkep82-eXIXLJ0oOUo1G"; int val1; int val2; int val3; int val4; #define button1 D7 #define button2 D6 #define button3 D1 void setup() { // put your setup code here, to run once: Serial.begin(115200); Blynk.begin(auth, ssid, pass); pinMode(button1, OUTPUT); pinMode(button2, OUTPUT); pinMode(button3, OUTPUT); } BLYNK_WRITE(V0){ val1 = param.asInt(); if (val1 == 1){ digitalWrite(button1, HIGH); delay(100); }else if(val1 == 0){ digitalWrite(button1, LOW); delay(100); } } BLYNK_WRITE(V1){ val2 = param.asInt(); if (val2 == 1){ digitalWrite(button2, HIGH); delay(100); }else if(val2 == 0){ digitalWrite(button2, LOW); delay(100); } } BLYNK_WRITE(V2){ val3 = param.asInt(); if (val3 == 1){ digitalWrite(button3, HIGH); delay(100); }else if(val3 == 0){ digitalWrite(button3, LOW); delay(100); } } BLYNK_WRITE(V3){ val4 = param.asInt(); if (val1 == HIGH){ analogWrite(button1, val4); }else{ val4 = 0; } } void loop() { // put your main code here, to run repeatedly: Blynk.run(); }
Editor is loading...
Leave a Comment