Skip to content

Commit 6dec3c3

Browse files
Merge pull request #10 from ayushsharma82/dev
1.0.9
2 parents 76993d2 + f60fc4e commit 6dec3c3

File tree

7 files changed

+30
-36
lines changed

7 files changed

+30
-36
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ NetWizard works on the following microcontrollers/boards:
5151
<br/>
5252
<br/>
5353

54-
## Looking for more? Upgrade to Pro.
54+
## Looking for more? Upgrade to Pro
5555

5656
Netwizard Pro comes with the following extended functionality:
5757

examples/AsyncDemo/AsyncDemo.ino

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,22 @@
1313
1414
Works with following hardware:
1515
- ESP32
16-
- RP2040 (with WiFi) (Example: Raspberry Pi Pico W)
16+
- RP2040+W (Example: Raspberry Pi Pico W)
1717
1818
Important note for RP2040 users:
1919
- RP2040 requires LittleFS partition for saving credentials.
2020
Without LittleFS partition, the app will fail to persist any data.
2121
Make sure to select Tools > Flash Size > "2MB (Sketch 1MB, FS 1MB)" option.
22-
- Doesn't works with bare RP2040, it requires WiFi module/chip (network co-processor)
22+
- Doesn't work with bare RP2040, it requires WiFi module/chip (network co-processor)
2323
like in Pico W for NetWizard to work.
2424
25-
NOTE: Asnyc mode required AsyncWebServer dependency and
25+
NOTE: Async mode requires ESPAsyncWebServer dependency and
2626
please make sure to enable async flag in NetWizard.h as per the docs:
2727
https://docs.netwizard.pro/async-mode
2828
2929
-------------------------------
3030
3131
Upgrade to NetWizard Pro: https://netwizard.pro
32-
3332
*/
3433

3534
#if defined(ESP32)
@@ -50,7 +49,7 @@ NetWizard NW(&server);
5049
NetWizardParameter nw_header(&NW, NW_HEADER, "MQTT");
5150
NetWizardParameter nw_divider1(&NW, NW_DIVIDER);
5251
NetWizardParameter nw_mqtt_host(&NW, NW_INPUT, "Host", "", "mqtt.example.com");
53-
NetWizardParameter nw_mqtt_port(&NW, NW_INPUT, "Port", "1883");
52+
NetWizardParameter nw_mqtt_port(&NW, NW_INPUT, "Port", "", "1883");
5453

5554
void setup(void) {
5655
delay(3000);

examples/Demo/Demo.ino

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@
1313
1414
Works with following hardware:
1515
- ESP32
16-
- RP2040 (with WiFi) (Example: Raspberry Pi Pico W)
17-
16+
- RP2040+W (Example: Raspberry Pi Pico W)
1817
1918
Important note for RP2040 users:
2019
- RP2040 requires LittleFS partition for saving credentials.
2120
Without LittleFS partition, the app will fail to persist any data.
2221
Make sure to select Tools > Flash Size > "2MB (Sketch 1MB, FS 1MB)" option.
23-
- If using bare RP2040, it requires WiFi module like Pico W for NetWizard to work.
22+
- Doesn't work with bare RP2040, it requires WiFi module/chip (network co-processor)
23+
like in Pico W for NetWizard to work.
2424
2525
-------------------------------
2626
2727
Upgrade to NetWizard Pro: https://netwizard.pro
28-
2928
*/
3029

3130
#include <WebServer.h>

library.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
"platforms": ["espressif8266", "raspberrypi"]
3636
}
3737
],
38-
"version": "1.0.8",
38+
"version": "1.0.9",
3939
"frameworks": "arduino",
40-
"platforms": ["espressif32", "raspberrypi"]
40+
"platforms": ["espressif32", "raspberrypi"],
41+
"build": {
42+
"libCompatMode": "strict"
43+
}
4144
}

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=NetWizard
2-
version=1.0.8
2+
version=1.0.9
33
author=Ayush Sharma
44
category=Communication
55
maintainer=Ayush Sharma <[email protected]>

src/NetWizard.cpp

+13-23
Original file line numberDiff line numberDiff line change
@@ -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

src/NetWizard.h

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Upgrade to NetWizard Pro: https://netwizard.pro
4343
#include "ESP8266WiFi.h"
4444
#if NETWIZARD_USE_ASYNC_WEBSERVER == 1
4545
#include "ESPAsyncTCP.h"
46+
#include "AsyncJson.h"
4647
#include "ESPAsyncWebServer.h"
4748
#define NETWIZARD_WEBSERVER AsyncWebServer
4849
#define NETWIZARD_REQ_HANDLER AsyncWebHandler
@@ -56,6 +57,7 @@ Upgrade to NetWizard Pro: https://netwizard.pro
5657
#include "WiFi.h"
5758
#if NETWIZARD_USE_ASYNC_WEBSERVER == 1
5859
#include "AsyncTCP.h"
60+
#include "AsyncJson.h"
5961
#include "ESPAsyncWebServer.h"
6062
#define NETWIZARD_WEBSERVER AsyncWebServer
6163
#define NETWIZARD_REQ_HANDLER AsyncWebHandler
@@ -69,6 +71,7 @@ Upgrade to NetWizard Pro: https://netwizard.pro
6971
#include "WiFi.h"
7072
#if NETWIZARD_USE_ASYNC_WEBSERVER == 1
7173
#include "AsyncTCP_RP2040W.h"
74+
#include "AsyncJson.h"
7275
#include "ESPAsyncWebServer.h"
7376
#define NETWIZARD_WEBSERVER AsyncWebServer
7477
#define NETWIZARD_REQ_HANDLER AsyncWebHandler

0 commit comments

Comments
 (0)