redirect() with ESP.restart() or ESP.reset() does not function
v1.9.1 ESPAsyncWebServer nodeMCUv2
Hello,
if redirect() methods works, I see it fails to work with ESP.restart() or ESP.reset()
I want to reboot if requested in the url to reboot, with 192.168.x.x/modeReboot as the redirect (fails to be excuted?) with the restart instruction, the html refresh makes the esp endlessly reboot, till the moment one changes the url.
AsyncWebServer gasyncSrv(80);
gasyncSrv.on("/modeReboot", HTTP_GET, [](AsyncWebServerRequest *request){
// you must leave this url otherwise infinite reboot
Serial.println("reboot change url");
request->redirect("/");
ESP.restart(); // make ESP8266 crash,
// reboots but as url is not redirected to root or any other(stays on /modeReboot), endlessly reboot
// commenting ESP.restart(); then the redirect() method works splendid
});
Error in Serial monitor:
reboot change url
⸮
ets Jan 8 2013,rst cause:2, boot mode:(3,7)
load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v0004d900
~ld
Thanks
Handling async events must be kept short and without system calls. I had same issue and got around by creating a global variable... uint16_t BackgroungCommand =0; Set this variable in your async response. Check it in loop() and execute your desired command and clear it.
Things like this are the reason that in general you should not use a GET request to perform actions, especially actions that would be problematic if the happened by accident. This is what POST is for, and using POST would avoid this problem because when it reconnects the browser would ask if you wanted to resubmit or not.
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.