ESPAsyncWebServer icon indicating copy to clipboard operation
ESPAsyncWebServer copied to clipboard

redirect() with ESP.restart() or ESP.reset() does not function

Open artofit opened this issue 3 years ago • 3 comments

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

artofit avatar Oct 27 '22 18:10 artofit

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.

stefann63 avatar Dec 02 '22 23:12 stefann63

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.

jasonk avatar Dec 10 '22 01:12 jasonk

[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.

stale[bot] avatar May 22 '23 01:05 stale[bot]