@@ -97,7 +97,7 @@ void NetWizard::autoConnect(const char* ssid, const char* password) {
97
97
unsigned long startMillis = millis ();
98
98
unsigned long lastConnectMillis = startMillis;
99
99
100
- while ((unsigned long )(millis () - startMillis) < NETWIZARD_CONNECT_TIMEOUT ) {
100
+ while ((unsigned long )(millis () - startMillis) < _nw. sta . timeout ) {
101
101
yield ();
102
102
this ->loop ();
103
103
@@ -351,8 +351,8 @@ void NetWizard::loop() {
351
351
}
352
352
}
353
353
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 )) {
356
356
_stopPortal ();
357
357
_nw.portal .exit .flag = false ;
358
358
_nw.portal .exit .millis = 0 ;
@@ -789,7 +789,7 @@ void NetWizard::_startHTTP() {
789
789
}
790
790
}).setFilter (this ->_onAPFilter );
791
791
792
- _save_handler = &_server-> on (" /netwizard/save" , HTTP_POST, [&](AsyncWebServerRequest *request) {
792
+ _save_handler = new AsyncCallbackJsonWebHandler (" /netwizard/save" , [&](AsyncWebServerRequest *request, JsonVariant &json) {
793
793
if (_nw.portal .auth .enabled && !request->authenticate (_nw.portal .auth .username .c_str (), _nw.portal .auth .password .c_str ())) {
794
794
return request->requestAuthentication ();
795
795
}
@@ -798,21 +798,6 @@ void NetWizard::_startHTTP() {
798
798
return request->send (503 , " text/plain" , " Busy" );
799
799
}
800
800
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
-
816
801
// check if JSON object is valid
817
802
if (!json.is <JsonObject>() || json.size () == 0 ) {
818
803
NETWIZARD_DEBUG_MSG (" Invalid json\n " );
@@ -841,7 +826,10 @@ void NetWizard::_startHTTP() {
841
826
}
842
827
843
828
return request->send (200 , " text/plain" , " OK" );
844
- }).setFilter (this ->_onAPFilter );
829
+ });
830
+
831
+ _save_handler->setFilter (this ->_onAPFilter );
832
+ _server->addHandler (_save_handler);
845
833
846
834
_clear_handler = &_server->on (" /netwizard/clear" , HTTP_POST, [&](AsyncWebServerRequest *request){
847
835
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() {
856
844
}
857
845
}).setFilter (this ->_onAPFilter );
858
846
859
- _exit_handler = &_server->on (" /netwizard/exit" , HTTP_GET , [&](AsyncWebServerRequest *request){
847
+ _exit_handler = &_server->on (" /netwizard/exit" , HTTP_POST , [&](AsyncWebServerRequest *request){
860
848
if (_nw.portal .auth .enabled && !request->authenticate (_nw.portal .auth .username .c_str (), _nw.portal .auth .password .c_str ())){
861
849
return request->requestAuthentication ();
862
850
}
@@ -866,14 +854,16 @@ void NetWizard::_startHTTP() {
866
854
}
867
855
868
856
if (!_nw.portal .exit .flag ) {
869
- _nw.portal .exit .flag = true ;
870
857
_nw.portal .exit .millis = millis ();
858
+ _nw.portal .exit .flag = true ;
871
859
}
872
860
return request->send (200 , " text/plain" , " OK" );
873
861
}).setFilter (this ->_onAPFilter );
874
862
875
863
_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);
877
867
});
878
868
879
869
#else
0 commit comments