ESP32 Boot Loop

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

I don't see the loop, but first is the sketch one of the examples?

no its not a example

No clue, but I would remove the HTML in case there is something weird in there.

i doubt its that ive tested some simple examples and sometimes they do work then i test it again and they dont

You should never discount an idea unless you can disprove the idea.

  1. Where is the "loop" you mentioned?
  2. Try removing HTML
  3. Try running a minimal sketch
  4. How many devices are you running off the ESP¿
  5. What are their power requirements?

Normally I would drop you for being so disrespectful, but I am feeling generous today. Try another board because if every sample you try is flaky then the board is the likely issue.
One other possibility is a bad cable. Don't question it, just replace it, they are cheap but more expensive than the board.

Hi @tozejj ,

Welcome to the forum..

check the pins..
pins 2,4,5 are strapping pins..
esp32-pinout-reference-gpios

good luck.. ~q

sorry if i sound disrepectful english is not my first language
but i have tested another cable

Ok, so have you tested with the html removed? Have you tried a simple Blink sketch?

No boot loop occurs, please specify what you mean.

Since no '.' are printed, it is crashing at WiFi.begin(). That is commonly due to an inadequate power supply, as the radio draws a lot of current when transmitting.

Make certain that the power supply can deliver at least 500 mA.

Have you selected the correct board, matching the one you're actually using? A bootloop like the one you posted is usually typical when the user program doesn’t even run, and this can often be due to an incorrect board configuration.

As suggested, it could also depend on the pins being used. Try disconnecting all external hardware from the pins and check if the bootloop disappears. If it does, replace the current pins with safer ones (e.g., GPIO21, GPIO22, GPIO23…).