Skip to content

Commit 41f7579

Browse files
committed
Resolve issue with AP.
Fix newly introduced null pointer in AuthenticationService.
1 parent f77428e commit 41f7579

9 files changed

+39
-18
lines changed

lib/framework/APSettingsService.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#include <APSettingsService.h>
22

3-
APSettingsService::APSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : AdminSettingsService(server, fs, securityManager, AP_SETTINGS_SERVICE_PATH, AP_SETTINGS_FILE) {
4-
onConfigUpdated();
5-
}
3+
APSettingsService::APSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : AdminSettingsService(server, fs, securityManager, AP_SETTINGS_SERVICE_PATH, AP_SETTINGS_FILE) {}
64

75
APSettingsService::~APSettingsService() {}
86

7+
void APSettingsService::begin() {
8+
SettingsService::begin();
9+
onConfigUpdated();
10+
}
11+
912
void APSettingsService::loop() {
1013
unsigned long currentMillis = millis();
1114
unsigned long manageElapsed = (unsigned long)(currentMillis - _lastManaged);
@@ -80,7 +83,4 @@ void APSettingsService::writeToJsonObject(JsonObject& root) {
8083

8184
void APSettingsService::onConfigUpdated() {
8285
_lastManaged = millis() - MANAGE_NETWORK_DELAY;
83-
84-
// stop softAP - forces reconfiguration in loop()
85-
stopAP();
8686
}

lib/framework/APSettingsService.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class APSettingsService : public AdminSettingsService {
2626
APSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
2727
~APSettingsService();
2828

29+
void begin();
2930
void loop();
3031

3132
protected:
@@ -49,7 +50,7 @@ class APSettingsService : public AdminSettingsService {
4950

5051
void manageAP();
5152
void startAP();
52-
void stopAP();
53+
void stopAP() ;
5354
void handleDNS();
5455

5556
};

lib/framework/AuthenticationService.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <AuthenticationService.h>
22

3-
AuthenticationService::AuthenticationService(AsyncWebServer* server, SecurityManager* securityManager) {
3+
AuthenticationService::AuthenticationService(AsyncWebServer* server, SecurityManager* securityManager) : _securityManager(securityManager) {
44
server->on(VERIFY_AUTHORIZATION_PATH, HTTP_GET, std::bind(&AuthenticationService::verifyAuthorization, this, std::placeholders::_1));
55

66
_signInHandler.setUri(SIGN_IN_PATH);

lib/framework/ESP8266React.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs):
3939
#endif
4040
}
4141

42+
void ESP8266React::begin() {
43+
_securitySettingsService.begin();
44+
_wifiSettingsService.begin();
45+
_apSettingsService.begin();
46+
_ntpSettingsService.begin();
47+
_otaSettingsService.begin();
48+
}
49+
4250
void ESP8266React::loop() {
4351
_wifiSettingsService.loop();
4452
_apSettingsService.loop();

lib/framework/ESP8266React.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class ESP8266React {
3030
public:
3131

3232
ESP8266React(AsyncWebServer* server, FS* fs);
33-
33+
34+
void begin();
3435
void loop();
3536

3637
SecurityManager* getSecurityManager(){

lib/framework/SettingsService.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ class SettingsService : public SettingsPersistence {
3131
_updateHandler.setMaxContentLength(MAX_SETTINGS_SIZE);
3232
_updateHandler.onRequest(std::bind(&SettingsService::updateConfig, this, std::placeholders::_1, std::placeholders::_2));
3333
server->addHandler(&_updateHandler);
34+
}
35+
36+
virtual ~SettingsService() {}
3437

38+
void begin() {
3539
// read the initial data from the file system
3640
readFromFS();
3741
}
3842

39-
virtual ~SettingsService() {}
40-
4143
protected:
4244
char const* _servicePath;
4345
AsyncJsonWebHandler _updateHandler;

lib/framework/WiFiSettingsService.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, Securit
55
WiFi.persistent(false);
66
WiFi.setAutoReconnect(false);
77

8-
// Force WiFi config to be applied when loop() called
9-
reconfigureWiFiConnection();
10-
118
#if defined(ESP8266)
129
_onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1));
1310
#elif defined(ESP_PLATFORM)
@@ -20,6 +17,11 @@ WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, Securit
2017

2118
WiFiSettingsService::~WiFiSettingsService() {}
2219

20+
void WiFiSettingsService::begin() {
21+
SettingsService::begin();
22+
reconfigureWiFiConnection();
23+
}
24+
2325
void WiFiSettingsService::readFromJsonObject(JsonObject& root){
2426
_ssid = root["ssid"] | "";
2527
_password = root["password"] | "";

lib/framework/WiFiSettingsService.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class WiFiSettingsService : public AdminSettingsService {
1515
WiFiSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
1616
~WiFiSettingsService();
1717

18+
void begin();
1819
void loop();
1920

2021
protected:

src/main.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@
55
#define SERIAL_BAUD_RATE 115200
66

77
AsyncWebServer server(80);
8-
ESP8266React framework(&server, &SPIFFS);
9-
DemoProject demoProject = DemoProject(&server, &SPIFFS, framework.getSecurityManager());
8+
ESP8266React esp8266React(&server, &SPIFFS);
9+
DemoProject demoProject = DemoProject(&server, &SPIFFS, esp8266React.getSecurityManager());
1010

1111
void setup() {
1212
// start serial and filesystem
1313
Serial.begin(SERIAL_BAUD_RATE);
14+
15+
// start the file system (must be done before starting the framework)
1416
SPIFFS.begin();
15-
17+
18+
// start the framework and demo project
19+
esp8266React.begin();
20+
demoProject.begin();
21+
1622
// start the server
1723
server.begin();
1824
}
1925

2026
void loop() {
2127
// run the framework's loop function
22-
framework.loop();
28+
esp8266React.loop();
2329

2430
// run the demo project's loop function
2531
demoProject.loop();

0 commit comments

Comments
 (0)