0% found this document useful (0 votes)
17 views4 pages

Program Led Esp8266 GPT

Pake chatgpt

Uploaded by

Penaple Pen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Program Led Esp8266 GPT

Pake chatgpt

Uploaded by

Penaple Pen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <ESP8266WiFi.

h>

#include <ESP8266WebServer.h>

Const char* ssid = “”; // NAMA KALIAN

Const char* password = “”; // ISIKAN PASSWORD

ESP8266WebServer server(80);

Bool LEDstatus = LOW;

Void setup() {

Serial.begin(9600);

pinMode(LED_BUILTIN, 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(LED_BUILTIN, HIGH);

} else {

digitalWrite(LED_BUILTIN, 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 = “<!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: #3498db; }\n”;

Ptr += “.button-on:active { background-color: #2980b9; }\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>Dengan Access Point(AP) Mode</h3>\n”;

If (LEDstatus) {

Ptr += “<p>BLUE LED: ON</p><a class=\”button button-off\”


href=\”/ledoff\”>OFF</a>\n”;

} else {

Ptr += “<p>BLUE LED: OFF</p><a class=\”button button-on\”


href=\”/ledon\”>ON</a>\n”;

}
Ptr += “</body>\n”;

Ptr += “</html>\n”;

Return ptr;

You might also like