ESP32 goes into a boot loop when connecting to wifi

DGaming
Posts: 1
Joined: Thu Dec 21, 2023 4:00 pm

ESP32 goes into a boot loop when connecting to wifi

Postby DGaming » Thu Dec 21, 2023 4:07 pm

so i was trying to make a home project, but when i uploaded this in my opinion working code the esp went into this boot loop
17:03:51.299 -> ets Jun 8 2016 00:22:57
17:03:51.299 ->
17:03:51.299 -> rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
17:03:51.299 -> configsip: 0, SPIWP:0xee
17:03:51.299 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
17:03:51.299 -> mode:DIO, clock div:1
17:03:51.299 -> load:0x3fff0030,len:1344
17:03:51.299 -> load:0x40078000,len:13964
17:03:51.299 -> load:0x40080400,len:3600
17:03:51.299 -> entry 0x400805f0
17:03:52.674 -> Connecting to WiFi...
17:03:53.682 -> Connecting to WiFi...
17:03:54.673 -> Connecting to WiFi...
17:03:54.673 -> Connected to WiFi

nothing is yet connected to the esp
the esp is powered by my pc but i tried another power supply, stil nothing
any help would be great
  1. #include <WiFi.h>
  2. #include <ESPAsyncWebServer.h>
  3. #include <Adafruit_Sensor.h>
  4. #include <DHT.h>
  5.  
  6. // Replace with your network credentials
  7. const char* ssid = "Kovar";
  8. const char* password = "xxxxx";
  9.  
  10. // Create an instance of the DHT sensor
  11. #define DHTPIN 2
  12. #define DHTTYPE DHT22
  13. DHT dht(DHTPIN, DHTTYPE);
  14.  
  15. // Define relay and sensor pins
  16. int relayPins[] = {4, 5, 6, 7, 8, 9, 10, 11};
  17. const int soilSensorPins[] = {34, 35, 32, 33, 25, 26};  // Soil humidity sensor pins on ESP32
  18.  
  19. // Define buzzer pin
  20. int buzzerPin = 12;
  21.  
  22. // Define watering duration
  23. const int wateringDuration = 10000;  // in milliseconds (10 seconds)
  24.  
  25. // Create an instance of the AsyncWebServer
  26. AsyncWebServer server(80);
  27.  
  28. // Array to store last watered times for each sensor
  29. unsigned long lastWateredTimes[6] = {0};
  30.  
  31. void setup() {
  32.   Serial.begin(115200);
  33.  
  34.   // Connect to Wi-Fi
  35.   WiFi.begin(ssid, password);
  36.   while (WiFi.status() != WL_CONNECTED) {
  37.     delay(1000);
  38.     Serial.println("Connecting to WiFi...");
  39.   }
  40.   Serial.println("Connected to WiFi");
  41.  
  42.   // Initialize DHT sensor
  43.   dht.begin();
  44.  
  45.   // Initialize relay and sensor pins
  46.   for (int i = 0; i < 8; i++) {
  47.     pinMode(relayPins[i], OUTPUT);
  48.   }
  49.  
  50.   // Set sensor pins as INPUT
  51.   for (int i = 0; i < 6; i++) {
  52.     pinMode(soilSensorPins[i], INPUT);
  53.   }
  54.  
  55.   // Set buzzer pin as OUTPUT
  56.   pinMode(buzzerPin, OUTPUT);
  57.  
  58.   // Route for root URL
  59.   server.on("/", HTTP_GET, handleRoot);
  60.  
  61.   // Route for manual watering
  62.   server.on("/water", HTTP_POST, handleWater);
  63.  
  64.   // Start server
  65.   server.begin();
  66. }
  67.  
  68. void loop() {
  69.   // Read sensor data and update web page
  70.   updateSensorData();
  71.  
  72.   // Check temperature and sound the buzzer if it's too low
  73.   checkTemperature();
  74.  
  75.   delay(10000);  // Delay for 10 seconds
  76. }
  77.  
  78. void handleRoot(AsyncWebServerRequest *request) {
  79.   String html = "<html><body>";
  80.   html += "<h1>Plant Watering System</h1>";
  81.  
  82.   // Display sensor data
  83.   for (int i = 0; i < 6; i++) {
  84.     html += "<p>Humidity Sensor " + String(i + 1) + ": " + String(analogRead(soilSensorPins[i])) + "</p>";
  85.     html += "<p>Last Watered: " + getLastWateredTime(i) + "</p>";
  86.   }
  87.  
  88.   // Manual watering form
  89.   html += "<form action='/water' method='post'>";
  90.   html += "<label for='relay'>Select Relay:</label>";
  91.   html += "<select name='relay'>";
  92.   for (int i = 0; i < 8; i++) {
  93.     html += "<option value='" + String(i) + "'>Relay " + String(i + 1) + "</option>";
  94.   }
  95.   html += "</select>";
  96.   html += "<label for='duration'>Watering Duration (seconds):</label>";
  97.   html += "<input type='number' name='duration' min='1' value='10'>";
  98.   html += "<input type='submit' value='Water Plants'>";
  99.   html += "</form>";
  100.  
  101.   html += "<p>Temperature: " + String(dht.readTemperature()) + " &#8451;</p>";
  102.   html += "<p>Humidity: " + String(dht.readHumidity()) + " %</p>";
  103.  
  104.   html += "</body></html>";
  105.   request->send(200, "text/html", html);
  106. }
  107.  
  108. void updateSensorData() {
  109.   // Update sensor data on the web page
  110.   // Activate the relay corresponding to the sensor for 10 seconds if humidity is below 50%
  111.   for (int i = 0; i < 6; i++) {
  112.     int humidity = analogRead(soilSensorPins[i]);
  113.     if (humidity < 50) {
  114.       activateRelay(i);
  115.       delay(wateringDuration);
  116.       deactivateRelay(i);
  117.       updateLastWateredTime(i);
  118.     }
  119.   }
  120. }
  121.  
  122. void checkTemperature() {
  123.   // Check temperature and sound the buzzer if it's too low (below 15°C)
  124.   float temperature = dht.readTemperature();
  125.   if (temperature < 15) {
  126.     digitalWrite(buzzerPin, HIGH);
  127.     // You can add code here to display a warning popup on the web page
  128.   } else {
  129.     digitalWrite(buzzerPin, LOW);
  130.   }
  131. }
  132.  
  133. void activateRelay(int relayIndex) {
  134.   // Activate the specified relay
  135.   digitalWrite(relayPins[relayIndex], HIGH);
  136. }
  137.  
  138. void deactivateRelay(int relayIndex) {
  139.   // Deactivate the specified relay
  140.   digitalWrite(relayPins[relayIndex], LOW);
  141. }
  142.  
  143. String getLastWateredTime(int sensorIndex) {
  144.   // Return the last watered time for the specified sensor
  145.   unsigned long lastWateredTime = lastWateredTimes[sensorIndex];
  146.   return (lastWateredTime == 0) ? "N/A" : String(lastWateredTime);
  147. }
  148.  
  149. void updateLastWateredTime(int sensorIndex) {
  150.   // Update the last watered time for the specified sensor
  151.   lastWateredTimes[sensorIndex] = millis();
  152. }
  153.  
  154. void handleWater(AsyncWebServerRequest *request) {
  155.   // Handle manual watering form submission
  156.   String relayIndexStr = request->arg("relay");
  157.   String durationStr = request->arg("duration");
  158.  
  159.   if (relayIndexStr.length() > 0 && durationStr.length() > 0) {
  160.     int relayIndex = relayIndexStr.toInt();
  161.     int wateringDuration = durationStr.toInt() * 1000;
  162.  
  163.     activateRelay(relayIndex);
  164.     delay(wateringDuration);
  165.     deactivateRelay(relayIndex);
  166.     updateLastWateredTime(relayIndex);
  167.   }
  168.  
  169.   request->redirect("/");
  170. }

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32 goes into a boot loop when connecting to wifi

Postby lbernstone » Fri Dec 22, 2023 4:16 pm

You say boot loop, but your output shows the WiFi looping, not the system.
Boot loops during wifi initialization are 99.9% caused by power issues. This is typically an underpowered LDO on board, but can also be insufficient capacitance (the power draw goes from ~100mA to 500mA, which causes the voltage on the rail to drop). You need a power supply rated for 800mA. Is this a dev board or custom?

Who is online

Users browsing this forum: No registered users and 36 guests