From 0994c4b3f869cddc827d677d92d112cf6a43df6e Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Fri, 11 Mar 2022 08:34:08 -0600 Subject: [PATCH] regression, webserver callbacks before reset crashes any webserver event handlers bound before the webserver new reset would cause memory access issues when triggered. Should remove all events on reset or make memory safe, not sure if this is the correct way to be reseting the webserver, but there were issues with the ports not releasing etc. --- WiFiManager.cpp | 17 +++++++++-------- .../OnDemandConfigPortal.ino | 3 ++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 8f5d49d..e619f00 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -587,6 +587,15 @@ void WiFiManager::setupHTTPServer(){ } server.reset(new WM_WebServer(_httpPort)); + // This is not the safest way to reset the webserver, it can cause crashes on callbacks initilized before this and since its a shared pointer... + + if ( _webservercallback != NULL) { + #ifdef WM_DEBUG_LEVEL + DEBUG_WM(DEBUG_VERBOSE,F("[CB] _webservercallback calling")); + #endif + _webservercallback(); + } + // @todo add a new callback maybe, after webserver started, callback cannot override handlers, but can grab them first /* Setup httpd callbacks, web pages: root, wifi config pages, SO captive portal detectors and not found. */ @@ -628,14 +637,6 @@ void WiFiManager::setupDNSD(){ void WiFiManager::setupConfigPortal() { - if ( _webservercallback != NULL) { - #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[CB] _webservercallback calling")); - #endif - _webservercallback(); - } - // @todo add a new callback maybe, after webserver started, callback cannot override handlers, but can grab them first - setupHTTPServer(); if(_preloadwifiscan) WiFi_scanNetworks(true,true); // preload wifiscan , async diff --git a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino index ff22a13..d2bcce2 100644 --- a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -24,6 +24,7 @@ WiFiManager wm; // TEST OPTION FLAGS bool TEST_CP = false; // always start the configportal, even if ap found +bool TEST_CP = true; // always start the configportal, even if ap found int TESP_CP_TIMEOUT = 90; // test cp timeout bool TEST_NET = true; // do a network test after connect, (gets ntp time) @@ -55,7 +56,7 @@ void saveParamCallback(){ } void bindServerCallback(){ - // wm.server->on("/custom",handleRoute); // this is now crashing esp32 for some reason + wm.server->on("/custom",handleRoute); // this is now crashing esp32 for some reason // wm.server->on("/info",handleRoute); // you can override wm! }