Hi, I am making a project using the esp32-c3. I have run into a strange problem. My code started to boot loop and in order to make it accept connections again I had to remove all components. After I did that I started to try and see what the problem is. I have narrowed it down, but it is very strange. This is my loop():
void loop() {
server.handleClient();
delay(1000);
looped();
}
It works fine like this, but add anything in the loop. Doesn't matter what it is, Variable declaration, Serial print, etc. It just starts bootlooping and I have no idea why in the world this takes place. Guru Meditation Error: Core 0 panic'ed (Interrupt wdt timeout on CPU0).
The rest of the main file
#include <WiFi.h>
#include <Preferences.h>
#include <WebServer.h>
#include "esp32/rtc.h"
#include <FastLED.h>
#include "utils.h"
int count = 0;
bool Joanne = true;
WebServer server(80);
Preferences data;
HTTPClient http;
CRGB led[1];
bool wasNear = false;
int offtime = -1;
bool isNear() {if (digitalRead(D6) == HIGH){return true;}else{return false;}}
bool isCharging() {if (digitalRead(D0) == HIGH){return true;}else{return false;}}
bool wasCharging = false;
bool connectWifi() {
Serial.println("Checkpoint9");
String ssid = data.getString("ssid", "");
String password = data.getString("pass", "");
if (ssid.length() == 0 || password.length() == 0) {
return false;
}
Serial.println("Verbinden met netwerk...");
WiFi.begin(ssid.c_str(), password.c_str());
int timeout = 10; // 10 seconden timeout om verbinding te maken
while (WiFi.status() != WL_CONNECTED && timeout > 0) {
delay(1000);
timeout--;
}
Serial.println("Checkpoint10");
Serial.println("Verbonden?");
return isWiFiActive();
}
// Functie om AP-modus te starten
void startAPMode() {
WiFi.softAP("Snuffel", "123456789");
Serial.println("Access Point Started!");
server.on("/", handleData);
server.begin();
}
void stopAPMode() {
WiFi.softAPdisconnect(true);
server.stop();
}
bool isWiFiActive() {
return WiFi.status() == WL_CONNECTED;
}
void handleData() {
data.putString("ssid", server.arg("ssid"));
data.putString("pass", server.arg("pass"));
String testValue = server.arg("test");
if (testValue == "true") {
server.send(200, "text/plain", "SnuffelWuppieValidated");
} else {
if (connectWifi()) {
server.send(200, "text/plain", "Wifi Connected");
} else {
server.send(200, "text/plain", "Wifi Failed");
}
}
}
void getData() {
if (downloadData("NewData", Joanne).toInt() == 1) {
data.putString("Lkleur", downloadData("Lkleur", Joanne));
data.putString("Kkleur", downloadData("Kkleur", Joanne));
data.putInt("SlaapTijd", downloadData("SlaapTijd", Joanne).toInt());
data.putInt("OntwaakTijd", downloadData("OntwaakTijd", Joanne).toInt());
data.putInt("SlaapDuratie", downloadData("SlaapDuratie", Joanne).toInt());
uploadData("NewData", 0);
}
}
void looped() {
if (count == 10) {
if (!isWiFiActive()) {
connectWifi();
}
if (isCharging) {
getData();
}
if (downloadData("Slapen", !Joanne).toInt() == 1) {
setLed(data.getString("Lkleur"));
} else {
setLed(data.getString("Kkleur"));
}
count = 0;
}
count++;
}
void setup() {
Serial.begin(9600);
data.begin("Snuffel", false); // Open data
FastLED.addLeds<WS2812B, D10, GRB>(led, 1);
led[0] = CRGB(0, 0, 0);
FastLED.show();
pinMode(D6, INPUT);
pinMode(D0, INPUT);
http.begin("my url");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
if (!connectWifi()) {
startAPMode();
}
setupRTC();
}
void loop() {
server.handleClient();
delay(1000);
looped();
}