Buatinfo
Buatinfo
h"
#include "ESPAsyncWebServer.h"
#include <ESP32Servo.h>
// ini relay
#define NUM_RELAYS 1
Servo myservo;
// webserver 80
AsyncWebServer server(80);
//ini htmlnya
<!DOCTYPE HTML><html>
<head>
<meta charset="UTF-8">
<style>
html {font-family: "Times New Roman",serif; display: inline-block; text-align: center;}
h2 {font-size: 2.5rem;}
p {font-size: 1.5rem;}
.slider {position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; border-radius:
34px}
.slider:before {position: absolute; content: ""; height: 52px; width: 52px; left: 8px; bottom: 8px;
background-color: #fff; -webkit-transition: .4s; transition: .4s; border-radius: 68px}
</style>
</head>
<body>
%BUTTONPLACEHOLDER%
<div class="control-section">
<h3>Korden</h3>
<label class="switch">
<span class="slider"></span>
</label>
</div>
<script>
function toggleCheckbox(element) {
if(element.checked){
document.getElementById("lightStatus").innerHTML = "Menyala";
else {
document.getElementById("lightStatus").innerHTML = "Mati";
xhr.send();
function toggleServo(element) {
xhr.send();
</script>
</body>
</html>
)rawliteral";
if(var == "BUTTONPLACEHOLDER"){
return buttons;
return String();
if(RELAY_NO){
if(digitalRead(relayGPIOs[numRelay-1])){
return "";
else {
return "checked";
else {
if(digitalRead(relayGPIOs[numRelay-1])){
return "checked";
else {
return "";
return "";
void setup(){
// Serial port for debugging purposes
Serial.begin(115200);
pinMode(relayGPIOs[i-1], OUTPUT);
if(RELAY_NO){
digitalWrite(relayGPIOs[i-1], HIGH);
else{
digitalWrite(relayGPIOs[i-1], LOW);
// Initialize servo
ESP32PWM::allocateTimer(0);
// nyambungin wifi
WiFi.begin(ssid, password);
delay(1000);
Serial.println("Connecting to WiFi..");
Serial.println(WiFi.localIP());
// rute webpage
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
});
String inputMessage;
String inputParam;
String inputMessage2;
String inputParam2;
inputMessage = request->getParam(PARAM_INPUT_1)->value();
inputParam = PARAM_INPUT_1;
inputMessage2 = request->getParam(PARAM_INPUT_2)->value();
inputParam2 = PARAM_INPUT_2;
if(RELAY_NO){
Serial.print("NO ");
digitalWrite(relayGPIOs[inputMessage.toInt()-1], !inputMessage2.toInt());
else{
Serial.print("NC ");
digitalWrite(relayGPIOs[inputMessage.toInt()-1], inputMessage2.toInt());
else {
inputParam = "none";
Serial.println(inputMessage + inputMessage2);
if (request->hasParam("value")) {
myservo.write(angle);
Serial.println(angle);
});
server.begin();
void loop() {