Id like to specify that it has worked a couple of time but mostly it just keeps bootlooping: heres the code:
#include <WiFi.h>
#include <WebServer.h>
const char* ssid = "";
const char* password = "";
const int pa = 2, pf = 4, ea = 16, ef = 17, aa = 5, af = 18;
WebServer server(80); // Using WebServer instead of WiFiServer
// HTML Interface
const char MAIN_page[] PROGMEM = R"=====(
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Arial; text-align: center; margin: 0 auto; padding: 20px;}
.btn {
padding: 15px 25px;
font-size: 18px;
margin: 10px;
border-radius: 8px;
border: none;
color: white;
cursor: pointer;
}
.open {background-color: #4CAF50;}
.close {background-color: #f44336;}
.status {
padding: 15px;
margin: 15px;
font-weight: bold;
font-size: 20px;
}
</style>
</head>
<body>
<h1>ESP32 Control Panel</h1>
<div>
<h2>Portão</h2>
<button class="btn open" onclick="control('pa')">Abrir Portão</button>
<button class="btn close" onclick="control('pf')">Fechar Portão</button>
</div>
<div class="status" id="status">Pronto</div>
<script>
function control(cmd) {
document.getElementById("status").innerHTML = "Processando...";
fetch("/" + cmd)
.then(response => response.text())
.then(data => {
document.getElementById("status").innerHTML = data;
})
.catch(err => {
document.getElementById("status").innerHTML = "Erro: " + err;
});
}
</script>
</body>
</html>
)=====";
void setup() {
Serial.begin(115200);
delay(2000);
// Initialize pins
pinMode(pa, OUTPUT); digitalWrite(pa, LOW);
pinMode(pf, OUTPUT); digitalWrite(pf, LOW);
pinMode(ea, OUTPUT); digitalWrite(ea, LOW);
pinMode(ef, OUTPUT); digitalWrite(ef, LOW);
pinMode(aa, OUTPUT); digitalWrite(aa, LOW);
pinMode(af, OUTPUT); digitalWrite(af, LOW);
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected! IP: " + WiFi.localIP());
// Web Server Handlers
server.on("/", handleRoot);
server.on("/pa", [](){ handleCommand(pa, "Portão Aberto"); });
server.on("/pf", [](){ handleCommand(pf, "Portão Fechado"); });
server.on("/ea", [](){ handleCommand(ea, "Estores Abertos"); });
server.on("/ef", [](){ handleCommand(ef, "Estores Fechados"); });
server.on("/aa", [](){ handleCommand(aa, "Aquecimento Ligado"); });
server.on("/af", [](){ handleCommand(af, "Aquecimento Desligado"); });
server.begin();
}
void loop() {
server.handleClient();
}
void handleRoot() {
server.send(200, "text/html", MAIN_page);
}
void handleCommand(int pin, String message) {
digitalWrite(pin, HIGH);
delay(1000);
digitalWrite(pin, LOW);
server.send(200, "text/plain", message);
}
When it bootloops this is what appears on the serial monitor
mode:DIO, clock div:1
load:0x3fff0030,len:4916
load:0x40078000,len:16436
load:0x40080400,len:4
ho 8 tail 4 room 4
load:0x40080404,len:3524
entry 0x400805b8
ets Jul 29 2019 12:21:46
Any help is much appreciated, sorry i know its probly gonna be a extremely simple answer im new the the esp32s wifi capabilities