Reputation: 1
I am using an ESP232 devkit and i am trying to start an Access Point where i can enter WiFi data, which then is Used to setup a WiFi Webserver to control Data. But whenever i enter wrong wifi data, it sets of the WatchDog timer. When i enter the right WiFi Data it connects and works.
19:18:44:830 -> Trying to connect...
19:18:45:330 -> Trying to connect...
19:18:45:332 -> debug
19:18:45:333 -> debug4
19:18:50:330 -> E (20302) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
19:18:50:339 -> E (20302) task_wdt: - async_tcp (CPU 0/1)
19:18:50:343 -> E (20302) task_wdt: Tasks currently running:
19:18:50:347 -> E (20302) task_wdt: CPU 0: IDLE
19:18:50:350 -> E (20302) task_wdt: CPU 1: loopTask
19:18:50:353 -> E (20302) task_wdt: Aborting.
19:18:50:356 ->
19:18:50:356 -> abort() was called at PC 0x400e8e95 on core 0
19:18:50:360 ->
19:18:50:360 ->
19:18:50:361 -> Backtrace: 0x4008389d:0x3ffbec3c |<-CORRUPTED
19:18:50:365 ->
19:18:50:365 ->
19:18:50:365 ->
19:18:50:365 ->
19:18:50:365 -> ELF file SHA256: 12c7e27a4eeae93f
19:18:50:368 ->
19:18:50:846 -> Rebooting...
19:18:50:848 -> ets Jul 29 2019 12:21:46
This is the code i use right now
void startAPMode() {
if (apmode == true) {
WiFi.mode(WIFI_AP_STA);
WiFi.softAP(apSSID, apPassword);
apServer.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
request->send(200, "text/html", ap_mode_html);
});
apServer.on("/setup", HTTP_GET, [](AsyncWebServerRequest* request) {
if (request->hasParam("ssid") && request->hasParam("password")) {
String ssid = request->getParam("ssid")->value();
String password = request->getParam("password")->value();
WiFi.begin(ssid.c_str(), password.c_str());
unsigned long startTime = millis();
bool connectionSuccessful = false;
while (millis() - startTime < 10000) {
esp_task_wdt_reset(); // Reset Watchdog Timer
if (WiFi.status() == WL_CONNECTED) {
connectionSuccessful = true;
break;
}
delay(500);
Serial.println("Versuche zu verbinden...");
}
//esp_task_wdt_reset();
Serial.println("debug");
if (connectionSuccessful) {
IPAddress wifiIP = WiFi.localIP();
String response = R"html(
<!DOCTYPE html>
<html>
<head>
<title>Verbindung Erfolgreich</title>
<style>
html, body { font-family: Arial, sans-serif; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; flex-direction: column; }
.container { padding: 20px; border: 1px solid #ddd; border-radius: 5px; background-color: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.1); max-width: 90%; }
.ip-address { font-weight: bold; margin-top: 20px; padding: 10px; background-color: #e9ecef; border-radius: 5px; }
</style>
</head>
<body>
<div class='container'>
Verbindung erfolgreich! Bitte diese IP Adresse aufschreiben oder merken. Über diese IP Adresse kann nun immer die Fenstersteuerung aufgerufen werden!
<div class='ip-address'>Die IP Adresse für die Webseite ist: )html" + wifiIP.toString() + R"html(</div>
</div>
</body>
</html>
)html";
request->send(200, "text/html", response);
Serial.println("debug2");
setupWiFiAndWebServer();
Serial.println("debug3");
}
else {
esp_task_wdt_reset();
Serial.println("debug4");
//WiFi.disconnect(); // Optional: trennt die Verbindung, wenn nicht erfolgreich
String response = "Connection failed! <a href='/'>Try again</a>";
request->send(200, "text/html", response);
Serial.println("debug5");
startAPMode();
}
}
else {
esp_task_wdt_reset();
request->send(200, "text/html", "Missing data! <a href='/'>Back</a>");
startAPMode();
}
});
apServer.begin();
Serial.println("AP-Modus Webserver gestartet auf " + WiFi.softAPIP().toString());
}
}
Right now i am reseting the watchdog timer (i think) in the while loop where it checks if the connection was successful. If i dont do that reset it crashes in the while loop already. But since i have the WD reset, it crashes in the else{} part where I print "debug 4". It prints the "debug 4" on the serial monitor and after 5 seconds it crashes.
It should write Connection Failed and then i want it to go back to the Form where i can enter the data. The same for Missing Data.
I know my solution with reseting the timer all the time is no solution either so if you have and other solutions i am happy to hear them.
So i would be glad if anyone could help me resolving this issue! Thanks!
I entered the wrong Wifi Data and it reset the ESP32 because it triggered the Watchdog. I expected it to Print Connection failed but it reseted.
Upvotes: 0
Views: 415
Reputation: 4034
This is one of the common mistate many users of using the ESPAsyncTCP library made. I copy part of the README.md of the library here:
Important things to remember
- This is fully asynchronous server and as such does not run on the loop thread.
- You can not use yield or delay or any function that uses them inside the callbacks
- The server is smart enough to know when to close the connection and free resources
- You can not send more than one response to a single request
and do not attempt to establish a wifi connection from the callback also... If you need to, do it in the loop() for checking if the wifi is connected, if not call your own reconnect() function.
BTW, ESPAsyncTCP is one of a few Arduino libraries that provided the most comprehensive documentation (the README.md), read it.
Upvotes: 0