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! }