I'm using Arduino IDE(2.3.5) ESP8266 (3.1.2) and ESPAsyncWebServer (3.7.4), ESPAsyncTCP(2.0.0). I need to wifi scan the network an print the result of my web interface. If I use WiFiScanNetworks(), ESP8266 is Soft WDT reset. The same thing happens when I use yield(). My test code is as follows
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
// Create AsyncWebServer object on port 80
AsyncWebServer web_server(80);
// Replace with your network credentials
const char* ssid = "your SSID";
const char* password = "your Password";
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
<title>ESPAsyncWebServer</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,">
</head>
<body>
<h2>ESPAsyncWebServer</h2>
<h4>Use 'WiFi.scanNetworks();' or 'yield();' Soft WDT reset</h4>
<input type="button" onclick="location.href='/test_scan';" value="Test Scan" />
<input type="button" onclick="location.href='/test_yield';" value="Test yield" />
<input type="button" onclick="location.href='/test_normal';" value="Test normal" />
</body>
</html>
)rawliteral";
void setup(){
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
// Print ESP Local IP Address
Serial.println(WiFi.localIP());
// Route for root / web page
web_server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/html", index_html);
});
web_server.on("/test_scan", HTTP_GET, [](AsyncWebServerRequest *request){
int n = WiFi.scanNetworks();
//String value = "Total : " + String(n) + " networks found.";
request->send(200, "text/plain", "Test WiFi Scannetworks() PASS");
});
web_server.on("/test_yield", HTTP_GET, [](AsyncWebServerRequest *request){
yield();
request->send(200, "text/plain", "Test yield() PASS");
});
web_server.on("/test_normal", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/plain", "Test normal PASS");
});
web_server.begin();
}
void loop() {
}