@@ -97,7 +97,7 @@ void NetWizard::autoConnect(const char* ssid, const char* password) {
9797 unsigned long startMillis = millis ();
9898 unsigned long lastConnectMillis = startMillis;
9999
100- while ((unsigned long )(millis () - startMillis) < NETWIZARD_CONNECT_TIMEOUT ) {
100+ while ((unsigned long )(millis () - startMillis) < _nw. sta . timeout ) {
101101 yield ();
102102 this ->loop ();
103103
@@ -351,8 +351,8 @@ void NetWizard::loop() {
351351 }
352352 }
353353
354- // If exit flag is set and more than 30 seconds have passed, stop portal
355- if (_nw.portal .exit .flag && ((unsigned long )(millis () - _nw.portal .exit .millis ) > 30000 )) {
354+ // If exit flag is set and more than NETWIZARD_EXIT_TIMEOUT milliseconds have passed, stop portal
355+ if (_nw.portal .exit .flag && ((unsigned long )(millis () - _nw.portal .exit .millis ) > NETWIZARD_EXIT_TIMEOUT )) {
356356 _stopPortal ();
357357 _nw.portal .exit .flag = false ;
358358 _nw.portal .exit .millis = 0 ;
@@ -789,7 +789,7 @@ void NetWizard::_startHTTP() {
789789 }
790790 }).setFilter (this ->_onAPFilter );
791791
792- _save_handler = &_server-> on (" /netwizard/save" , HTTP_POST, [&](AsyncWebServerRequest *request) {
792+ _save_handler = new AsyncCallbackJsonWebHandler (" /netwizard/save" , [&](AsyncWebServerRequest *request, JsonVariant &json) {
793793 if (_nw.portal .auth .enabled && !request->authenticate (_nw.portal .auth .username .c_str (), _nw.portal .auth .password .c_str ())) {
794794 return request->requestAuthentication ();
795795 }
@@ -798,21 +798,6 @@ void NetWizard::_startHTTP() {
798798 return request->send (503 , " text/plain" , " Busy" );
799799 }
800800
801- // check if JSON object is available
802- if (request->hasArg (" plain" ) == false ) {
803- NETWIZARD_DEBUG_MSG (" Invalid request data\n " );
804- return request->send (400 , " text/plain" , " Request body not found" );
805- }
806-
807- #if ARDUINOJSON_VERSION_MAJOR == 7
808- JsonDocument json;
809- #else
810- DynamicJsonDocument json (NETWIZARD_CONFIG_JSON_SIZE);
811- #endif
812-
813- // parse JSON object
814- deserializeJson (json, request->arg (" plain" ));
815-
816801 // check if JSON object is valid
817802 if (!json.is <JsonObject>() || json.size () == 0 ) {
818803 NETWIZARD_DEBUG_MSG (" Invalid json\n " );
@@ -841,7 +826,10 @@ void NetWizard::_startHTTP() {
841826 }
842827
843828 return request->send (200 , " text/plain" , " OK" );
844- }).setFilter (this ->_onAPFilter );
829+ });
830+
831+ _save_handler->setFilter (this ->_onAPFilter );
832+ _server->addHandler (_save_handler);
845833
846834 _clear_handler = &_server->on (" /netwizard/clear" , HTTP_POST, [&](AsyncWebServerRequest *request){
847835 if (_nw.portal .auth .enabled && !request->authenticate (_nw.portal .auth .username .c_str (), _nw.portal .auth .password .c_str ())) {
@@ -856,7 +844,7 @@ void NetWizard::_startHTTP() {
856844 }
857845 }).setFilter (this ->_onAPFilter );
858846
859- _exit_handler = &_server->on (" /netwizard/exit" , HTTP_GET , [&](AsyncWebServerRequest *request){
847+ _exit_handler = &_server->on (" /netwizard/exit" , HTTP_POST , [&](AsyncWebServerRequest *request){
860848 if (_nw.portal .auth .enabled && !request->authenticate (_nw.portal .auth .username .c_str (), _nw.portal .auth .password .c_str ())){
861849 return request->requestAuthentication ();
862850 }
@@ -866,14 +854,16 @@ void NetWizard::_startHTTP() {
866854 }
867855
868856 if (!_nw.portal .exit .flag ) {
869- _nw.portal .exit .flag = true ;
870857 _nw.portal .exit .millis = millis ();
858+ _nw.portal .exit .flag = true ;
871859 }
872860 return request->send (200 , " text/plain" , " OK" );
873861 }).setFilter (this ->_onAPFilter );
874862
875863 _server->onNotFound ([](AsyncWebServerRequest *request){
876- return request->redirect (" /" );
864+ AsyncWebServerResponse *response = request->beginResponse (302 , " text/plain" , " " );
865+ response->addHeader (" Location" , String (" http://" ) + request->client ()->localIP ().toString ());
866+ request->send (response);
877867 });
878868
879869 #else
0 commit comments