diff --git a/lib/framework/APSettingsService.cpp b/lib/framework/APSettingsService.cpp index 71f09a8..98ceb58 100644 --- a/lib/framework/APSettingsService.cpp +++ b/lib/framework/APSettingsService.cpp @@ -1,6 +1,6 @@ #include -APSettingsService::APSettingsService(FS* fs, SecurityManager* securityManager) : AdminSettingsService(fs, securityManager, AP_SETTINGS_SERVICE_PATH, AP_SETTINGS_FILE) { +APSettingsService::APSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : AdminSettingsService(server, fs, securityManager, AP_SETTINGS_SERVICE_PATH, AP_SETTINGS_FILE) { onConfigUpdated(); } diff --git a/lib/framework/APSettingsService.h b/lib/framework/APSettingsService.h index fb2e9d5..0ff46fb 100644 --- a/lib/framework/APSettingsService.h +++ b/lib/framework/APSettingsService.h @@ -23,7 +23,7 @@ class APSettingsService : public AdminSettingsService { public: - APSettingsService(FS* fs, SecurityManager* securityManager); + APSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager); ~APSettingsService(); void loop(); diff --git a/lib/framework/APStatus.cpp b/lib/framework/APStatus.cpp index e0c399b..f8d1660 100644 --- a/lib/framework/APStatus.cpp +++ b/lib/framework/APStatus.cpp @@ -1,10 +1,8 @@ #include -APStatus::APStatus(SecurityManager* securityManager) :_securityManager(securityManager) {} - -void APStatus::init(AsyncWebServer *server){ - server->on(AP_STATUS_SERVICE_PATH, HTTP_GET, - _securityManager->wrapRequest(std::bind(&APStatus::apStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED) +APStatus::APStatus(AsyncWebServer* server, SecurityManager* securityManager) { + server->on(AP_STATUS_SERVICE_PATH, HTTP_GET, + securityManager->wrapRequest(std::bind(&APStatus::apStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED) ); } diff --git a/lib/framework/APStatus.h b/lib/framework/APStatus.h index d389052..773f743 100644 --- a/lib/framework/APStatus.h +++ b/lib/framework/APStatus.h @@ -22,13 +22,10 @@ class APStatus { public: - APStatus(SecurityManager* securityManager); - void init(AsyncWebServer *server); + APStatus(AsyncWebServer* server, SecurityManager* securityManager); private: - SecurityManager* _securityManager; - void apStatus(AsyncWebServerRequest *request); }; diff --git a/lib/framework/AdminSettingsService.h b/lib/framework/AdminSettingsService.h index cb5be59..e88e4d2 100644 --- a/lib/framework/AdminSettingsService.h +++ b/lib/framework/AdminSettingsService.h @@ -6,9 +6,8 @@ class AdminSettingsService : public SettingsService { public: - AdminSettingsService(FS* fs, SecurityManager* securityManager, char const* servicePath, char const* filePath): - SettingsService(fs, servicePath, filePath), _securityManager(securityManager) { - } + AdminSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager, char const* servicePath, char const* filePath): + SettingsService(server, fs, servicePath, filePath), _securityManager(securityManager) {} protected: // will validate the requests with the security manager diff --git a/lib/framework/AuthenticationService.cpp b/lib/framework/AuthenticationService.cpp index e56dd5d..9ae675c 100644 --- a/lib/framework/AuthenticationService.cpp +++ b/lib/framework/AuthenticationService.cpp @@ -1,19 +1,17 @@ #include -AuthenticationService::AuthenticationService(SecurityManager* securityManager) : _securityManager(securityManager) { +AuthenticationService::AuthenticationService(AsyncWebServer* server, SecurityManager* securityManager) { + server->on(VERIFY_AUTHORIZATION_PATH, HTTP_GET, std::bind(&AuthenticationService::verifyAuthorization, this, std::placeholders::_1)); + _signInHandler.setUri(SIGN_IN_PATH); _signInHandler.setMethod(HTTP_POST); _signInHandler.setMaxContentLength(MAX_AUTHENTICATION_SIZE); _signInHandler.onRequest(std::bind(&AuthenticationService::signIn, this, std::placeholders::_1, std::placeholders::_2)); + server->addHandler(&_signInHandler); } AuthenticationService::~AuthenticationService() {} -void AuthenticationService::init(AsyncWebServer* server) { - server->on(VERIFY_AUTHORIZATION_PATH, HTTP_GET, std::bind(&AuthenticationService::verifyAuthorization, this, std::placeholders::_1)); - server->addHandler(&_signInHandler); -} - /** * Verifys that the request supplied a valid JWT. */ diff --git a/lib/framework/AuthenticationService.h b/lib/framework/AuthenticationService.h index 06afd5f..472c4ef 100644 --- a/lib/framework/AuthenticationService.h +++ b/lib/framework/AuthenticationService.h @@ -15,14 +15,11 @@ class AuthenticationService { public: - AuthenticationService(SecurityManager* securityManager); + AuthenticationService(AsyncWebServer* server, SecurityManager* securityManager); ~AuthenticationService(); - void init(AsyncWebServer* server); - private: - // server instance - AsyncWebServer* _server; + SecurityManager* _securityManager; AsyncJsonWebHandler _signInHandler; diff --git a/lib/framework/ESP8266React.cpp b/lib/framework/ESP8266React.cpp index 4ac706e..ff43a37 100644 --- a/lib/framework/ESP8266React.cpp +++ b/lib/framework/ESP8266React.cpp @@ -1,40 +1,18 @@ #include -ESP8266React::ESP8266React(FS* fs): - _fs(fs), - _securitySettingsService(_fs), - _wifiSettingsService(_fs, &_securitySettingsService), - _apSettingsService(_fs, &_securitySettingsService), - _ntpSettingsService(_fs, &_securitySettingsService), - _otaSettingsService(_fs, &_securitySettingsService), - _authenticationService(&_securitySettingsService), - _wifiScanner(&_securitySettingsService), - _wifiStatus(&_securitySettingsService), - _ntpStatus(&_securitySettingsService), - _apStatus(&_securitySettingsService), - _systemStatus(&_securitySettingsService) { -} - -void ESP8266React::init(AsyncWebServer* server) { - // Start security settings service first - _securitySettingsService.init(server); - - // Core services - _wifiSettingsService.init(server); - _apSettingsService.init(server); - _ntpSettingsService.init(server); - _otaSettingsService.init(server); - _authenticationService.init(server); - - // Utility services - _wifiScanner.init(server); - _wifiStatus.init(server); - _ntpStatus.init(server); - _apStatus.init(server); - _systemStatus.init(server); - - - // Serving static resources from /www/ +ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs): + _securitySettingsService(server, fs), + _wifiSettingsService(server, fs, &_securitySettingsService), + _apSettingsService(server, fs, &_securitySettingsService), + _ntpSettingsService(server, fs, &_securitySettingsService), + _otaSettingsService(server, fs, &_securitySettingsService), + _authenticationService(server, &_securitySettingsService), + _wifiScanner(server, &_securitySettingsService), + _wifiStatus(server, &_securitySettingsService), + _ntpStatus(server, &_securitySettingsService), + _apStatus(server, &_securitySettingsService), + _systemStatus(server, &_securitySettingsService) { + // Serve static resources from /www/ server->serveStatic("/js/", SPIFFS, "/www/js/"); server->serveStatic("/css/", SPIFFS, "/www/css/"); server->serveStatic("/fonts/", SPIFFS, "/www/fonts/"); diff --git a/lib/framework/ESP8266React.h b/lib/framework/ESP8266React.h index dcd1e49..1f1ae42 100644 --- a/lib/framework/ESP8266React.h +++ b/lib/framework/ESP8266React.h @@ -29,9 +29,8 @@ class ESP8266React { public: - ESP8266React(FS* fs); - - void init(AsyncWebServer* server); + ESP8266React(AsyncWebServer* server, FS* fs); + void loop(); SecurityManager* getSecurityManager(){ @@ -40,8 +39,6 @@ class ESP8266React { private: - FS* _fs; - SecuritySettingsService _securitySettingsService; WiFiSettingsService _wifiSettingsService; diff --git a/lib/framework/NTPSettingsService.cpp b/lib/framework/NTPSettingsService.cpp index 5f9ae2d..7d8c571 100644 --- a/lib/framework/NTPSettingsService.cpp +++ b/lib/framework/NTPSettingsService.cpp @@ -1,6 +1,6 @@ #include -NTPSettingsService::NTPSettingsService(FS* fs, SecurityManager* securityManager) : AdminSettingsService(fs, securityManager, NTP_SETTINGS_SERVICE_PATH, NTP_SETTINGS_FILE) { +NTPSettingsService::NTPSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : AdminSettingsService(server, fs, securityManager, NTP_SETTINGS_SERVICE_PATH, NTP_SETTINGS_FILE) { #if defined(ESP8266) _onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(std::bind(&NTPSettingsService::onStationModeDisconnected, this, std::placeholders::_1)); diff --git a/lib/framework/NTPSettingsService.h b/lib/framework/NTPSettingsService.h index 8474fec..ae63586 100644 --- a/lib/framework/NTPSettingsService.h +++ b/lib/framework/NTPSettingsService.h @@ -21,7 +21,7 @@ class NTPSettingsService : public AdminSettingsService { public: - NTPSettingsService(FS* fs, SecurityManager* securityManager); + NTPSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager); ~NTPSettingsService(); void loop(); diff --git a/lib/framework/NTPStatus.cpp b/lib/framework/NTPStatus.cpp index 5b9df26..7f70d0c 100644 --- a/lib/framework/NTPStatus.cpp +++ b/lib/framework/NTPStatus.cpp @@ -1,10 +1,8 @@ #include -NTPStatus::NTPStatus(SecurityManager* securityManager) : _securityManager(securityManager) {} - -void NTPStatus::init(AsyncWebServer *server){ +NTPStatus::NTPStatus(AsyncWebServer* server, SecurityManager* securityManager) { server->on(NTP_STATUS_SERVICE_PATH, HTTP_GET, - _securityManager->wrapRequest(std::bind(&NTPStatus::ntpStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED) + securityManager->wrapRequest(std::bind(&NTPStatus::ntpStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED) ); } diff --git a/lib/framework/NTPStatus.h b/lib/framework/NTPStatus.h index a77b0f5..976ca42 100644 --- a/lib/framework/NTPStatus.h +++ b/lib/framework/NTPStatus.h @@ -23,12 +23,10 @@ class NTPStatus { public: - NTPStatus(SecurityManager* securityManager); - void init(AsyncWebServer *server); + NTPStatus(AsyncWebServer* server, SecurityManager* securityManager); private: - SecurityManager* _securityManager; void ntpStatus(AsyncWebServerRequest *request); }; diff --git a/lib/framework/OTASettingsService.cpp b/lib/framework/OTASettingsService.cpp index 1fed36c..7de85b4 100644 --- a/lib/framework/OTASettingsService.cpp +++ b/lib/framework/OTASettingsService.cpp @@ -1,6 +1,6 @@ #include -OTASettingsService::OTASettingsService(FS* fs, SecurityManager* securityManager) : AdminSettingsService(fs, securityManager, OTA_SETTINGS_SERVICE_PATH, OTA_SETTINGS_FILE) { +OTASettingsService::OTASettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : AdminSettingsService(server, fs, securityManager, OTA_SETTINGS_SERVICE_PATH, OTA_SETTINGS_FILE) { #if defined(ESP8266) _onStationModeGotIPHandler = WiFi.onStationModeGotIP(std::bind(&OTASettingsService::onStationModeGotIP, this, std::placeholders::_1)); #elif defined(ESP_PLATFORM) diff --git a/lib/framework/OTASettingsService.h b/lib/framework/OTASettingsService.h index 60bb9da..fa76ccb 100644 --- a/lib/framework/OTASettingsService.h +++ b/lib/framework/OTASettingsService.h @@ -23,7 +23,7 @@ class OTASettingsService : public AdminSettingsService { public: - OTASettingsService(FS* fs, SecurityManager* securityManager); + OTASettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager); ~OTASettingsService(); void loop(); @@ -52,4 +52,4 @@ class OTASettingsService : public AdminSettingsService { }; -#endif // end NTPSettingsService_h +#endif // end OTASettingsService_h diff --git a/lib/framework/SecuritySettingsService.cpp b/lib/framework/SecuritySettingsService.cpp index b8f4392..f512450 100644 --- a/lib/framework/SecuritySettingsService.cpp +++ b/lib/framework/SecuritySettingsService.cpp @@ -1,6 +1,6 @@ #include -SecuritySettingsService::SecuritySettingsService(FS* fs) : AdminSettingsService(fs, this, SECURITY_SETTINGS_PATH, SECURITY_SETTINGS_FILE), SecurityManager() {} +SecuritySettingsService::SecuritySettingsService(AsyncWebServer* server, FS* fs) : AdminSettingsService(server, fs, this, SECURITY_SETTINGS_PATH, SECURITY_SETTINGS_FILE), SecurityManager() {} SecuritySettingsService::~SecuritySettingsService() {} void SecuritySettingsService::readFromJsonObject(JsonObject& root) { diff --git a/lib/framework/SecuritySettingsService.h b/lib/framework/SecuritySettingsService.h index bc758e9..c46ed80 100644 --- a/lib/framework/SecuritySettingsService.h +++ b/lib/framework/SecuritySettingsService.h @@ -11,7 +11,7 @@ class SecuritySettingsService : public AdminSettingsService, public SecurityMana public: - SecuritySettingsService(FS* fs); + SecuritySettingsService(AsyncWebServer* server, FS* fs); ~SecuritySettingsService(); protected: diff --git a/lib/framework/SettingsService.h b/lib/framework/SettingsService.h index 3c447e8..b0317f7 100644 --- a/lib/framework/SettingsService.h +++ b/lib/framework/SettingsService.h @@ -23,25 +23,21 @@ class SettingsService : public SettingsPersistence { public: - SettingsService(FS* fs, char const* servicePath, char const* filePath): - SettingsPersistence(fs, filePath), _servicePath(servicePath) { + SettingsService(AsyncWebServer* server, FS* fs, char const* servicePath, char const* filePath): SettingsPersistence(fs, filePath), _servicePath(servicePath) { + server->on(_servicePath, HTTP_GET, std::bind(&SettingsService::fetchConfig, this, std::placeholders::_1)); + _updateHandler.setUri(servicePath); _updateHandler.setMethod(HTTP_POST); _updateHandler.setMaxContentLength(MAX_SETTINGS_SIZE); _updateHandler.onRequest(std::bind(&SettingsService::updateConfig, this, std::placeholders::_1, std::placeholders::_2)); - } - - virtual ~SettingsService() {} - - void init(AsyncWebServer* server) { - // configure fetch config handler - server->on(_servicePath, HTTP_GET, std::bind(&SettingsService::fetchConfig, this, std::placeholders::_1)); - server->addHandler(&_updateHandler); + server->addHandler(&_updateHandler); // read the initial data from the file system readFromFS(); } + virtual ~SettingsService() {} + protected: char const* _servicePath; AsyncJsonWebHandler _updateHandler; diff --git a/lib/framework/SimpleService.h b/lib/framework/SimpleService.h index 95d434b..0541a7c 100644 --- a/lib/framework/SimpleService.h +++ b/lib/framework/SimpleService.h @@ -59,9 +59,6 @@ private: protected: - // will serve setting endpoints from here - char const* _servicePath; - // reads the local config from the virtual void readFromJsonObject(JsonObject& root) {} virtual void writeToJsonObject(JsonObject& root) {} @@ -71,20 +68,18 @@ private: public: - SimpleService(char const* servicePath): _servicePath(servicePath) { + SimpleService(AsyncWebServer* server, char const* servicePath) { + server->on(servicePath, HTTP_GET, std::bind(&SimpleService::fetchConfig, this, std::placeholders::_1)); + _updateHandler.setUri(servicePath); _updateHandler.setMethod(HTTP_POST); _updateHandler.setMaxContentLength(MAX_SETTINGS_SIZE); _updateHandler.onRequest(std::bind(&SimpleService::updateConfig, this, std::placeholders::_1, std::placeholders::_2)); + server->addHandler(&_updateHandler); } virtual ~SimpleService() {} - void init(AsyncWebServer* server) { - server->on(_servicePath, HTTP_GET, std::bind(&SimpleService::fetchConfig, this, std::placeholders::_1)); - server->addHandler(&_updateHandler); - } - }; #endif // end SimpleService diff --git a/lib/framework/SystemStatus.cpp b/lib/framework/SystemStatus.cpp index 4eb5bcc..bcdd212 100644 --- a/lib/framework/SystemStatus.cpp +++ b/lib/framework/SystemStatus.cpp @@ -1,14 +1,12 @@ #include -SystemStatus::SystemStatus(SecurityManager* securityManager) : _securityManager(securityManager) {} - -void SystemStatus::init(AsyncWebServer *server) { +SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityManager) { server->on(SYSTEM_STATUS_SERVICE_PATH, HTTP_GET, - _securityManager->wrapRequest(std::bind(&SystemStatus::systemStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED) + securityManager->wrapRequest(std::bind(&SystemStatus::systemStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED) ); } - void SystemStatus::systemStatus(AsyncWebServerRequest *request) { +void SystemStatus::systemStatus(AsyncWebServerRequest *request) { AsyncJsonResponse * response = new AsyncJsonResponse(MAX_ESP_STATUS_SIZE); JsonObject root = response->getRoot(); #if defined(ESP8266) diff --git a/lib/framework/SystemStatus.h b/lib/framework/SystemStatus.h index ed60bcd..7858bee 100644 --- a/lib/framework/SystemStatus.h +++ b/lib/framework/SystemStatus.h @@ -21,13 +21,10 @@ class SystemStatus { public: - SystemStatus(SecurityManager* securityManager); - void init(AsyncWebServer* server); + SystemStatus(AsyncWebServer* server, SecurityManager* securityManager); private: - SecurityManager* _securityManager; - void systemStatus(AsyncWebServerRequest *request); }; diff --git a/lib/framework/WiFiScanner.cpp b/lib/framework/WiFiScanner.cpp index da34e1a..309cdd6 100644 --- a/lib/framework/WiFiScanner.cpp +++ b/lib/framework/WiFiScanner.cpp @@ -1,15 +1,13 @@ #include -WiFiScanner::WiFiScanner(SecurityManager* securityManager) : _securityManager(securityManager) {}; - -void WiFiScanner::init(AsyncWebServer* server) { +WiFiScanner::WiFiScanner(AsyncWebServer *server, SecurityManager* securityManager) { server->on(SCAN_NETWORKS_SERVICE_PATH, HTTP_GET, - _securityManager->wrapRequest(std::bind(&WiFiScanner::scanNetworks, this, std::placeholders::_1), AuthenticationPredicates::IS_ADMIN) + securityManager->wrapRequest(std::bind(&WiFiScanner::scanNetworks, this, std::placeholders::_1), AuthenticationPredicates::IS_ADMIN) ); server->on(LIST_NETWORKS_SERVICE_PATH, HTTP_GET, - _securityManager->wrapRequest(std::bind(&WiFiScanner::listNetworks, this, std::placeholders::_1), AuthenticationPredicates::IS_ADMIN) + securityManager->wrapRequest(std::bind(&WiFiScanner::listNetworks, this, std::placeholders::_1), AuthenticationPredicates::IS_ADMIN) ); -} +}; void WiFiScanner::scanNetworks(AsyncWebServerRequest *request) { if (WiFi.scanComplete() != -1){ diff --git a/lib/framework/WiFiScanner.h b/lib/framework/WiFiScanner.h index 74ea61e..e889da3 100644 --- a/lib/framework/WiFiScanner.h +++ b/lib/framework/WiFiScanner.h @@ -24,13 +24,10 @@ class WiFiScanner { public: - WiFiScanner(SecurityManager* securityManager); - void init(AsyncWebServer *server); + WiFiScanner(AsyncWebServer *server, SecurityManager* securityManager); private: - SecurityManager* _securityManager; - void scanNetworks(AsyncWebServerRequest *request); void listNetworks(AsyncWebServerRequest *request); diff --git a/lib/framework/WiFiSettingsService.cpp b/lib/framework/WiFiSettingsService.cpp index d6fe4ca..b8e54a9 100644 --- a/lib/framework/WiFiSettingsService.cpp +++ b/lib/framework/WiFiSettingsService.cpp @@ -1,10 +1,13 @@ #include -WiFiSettingsService::WiFiSettingsService(FS* fs, SecurityManager* securityManager) : AdminSettingsService(fs, securityManager, WIFI_SETTINGS_SERVICE_PATH, WIFI_SETTINGS_FILE) { - // Disable wifi config persistance and auto reconnect +WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : AdminSettingsService(server, fs, securityManager, WIFI_SETTINGS_SERVICE_PATH, WIFI_SETTINGS_FILE) { + // Disable WiFi config persistance and auto reconnect WiFi.persistent(false); WiFi.setAutoReconnect(false); + // Force WiFi config to be applied when loop() called + reconfigureWiFiConnection(); + #if defined(ESP8266) _onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1)); #elif defined(ESP_PLATFORM) @@ -17,11 +20,6 @@ WiFiSettingsService::WiFiSettingsService(FS* fs, SecurityManager* securityManage WiFiSettingsService::~WiFiSettingsService() {} -void WiFiSettingsService::init(AsyncWebServer* server) { - SettingsService::init(server); - reconfigureWiFiConnection(); -} - void WiFiSettingsService::readFromJsonObject(JsonObject& root){ _ssid = root["ssid"] | ""; _password = root["password"] | ""; diff --git a/lib/framework/WiFiSettingsService.h b/lib/framework/WiFiSettingsService.h index b967591..e5e6c7e 100644 --- a/lib/framework/WiFiSettingsService.h +++ b/lib/framework/WiFiSettingsService.h @@ -12,10 +12,9 @@ class WiFiSettingsService : public AdminSettingsService { public: - WiFiSettingsService(FS* fs, SecurityManager* securityManager); + WiFiSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager); ~WiFiSettingsService(); - void init(AsyncWebServer* server); void loop(); protected: diff --git a/lib/framework/WiFiStatus.cpp b/lib/framework/WiFiStatus.cpp index 09db75c..6c4f586 100644 --- a/lib/framework/WiFiStatus.cpp +++ b/lib/framework/WiFiStatus.cpp @@ -1,6 +1,9 @@ #include -WiFiStatus::WiFiStatus(SecurityManager* securityManager) : _securityManager(securityManager) { +WiFiStatus::WiFiStatus(AsyncWebServer* server, SecurityManager* securityManager) { + server->on(WIFI_STATUS_SERVICE_PATH, HTTP_GET, + securityManager->wrapRequest(std::bind(&WiFiStatus::wifiStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED) + ); #if defined(ESP8266) _onStationModeConnectedHandler = WiFi.onStationModeConnected(onStationModeConnected); _onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(onStationModeDisconnected); @@ -47,12 +50,6 @@ void WiFiStatus::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info) { } #endif -void WiFiStatus::init(AsyncWebServer* server) { - server->on(WIFI_STATUS_SERVICE_PATH, HTTP_GET, - _securityManager->wrapRequest(std::bind(&WiFiStatus::wifiStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED) - ); -} - void WiFiStatus::wifiStatus(AsyncWebServerRequest *request) { AsyncJsonResponse * response = new AsyncJsonResponse(MAX_WIFI_STATUS_SIZE); JsonObject root = response->getRoot(); diff --git a/lib/framework/WiFiStatus.h b/lib/framework/WiFiStatus.h index 05aa3a1..7132238 100644 --- a/lib/framework/WiFiStatus.h +++ b/lib/framework/WiFiStatus.h @@ -22,14 +22,10 @@ class WiFiStatus { public: - WiFiStatus(SecurityManager* securityManager); - - void init(AsyncWebServer* server); + WiFiStatus(AsyncWebServer* server, SecurityManager* securityManager); private: - SecurityManager* _securityManager; - #if defined(ESP8266) // handler refrences for logging important WiFi events over serial WiFiEventHandler _onStationModeConnectedHandler; diff --git a/src/DemoProject.cpp b/src/DemoProject.cpp index 20fc953..127f0eb 100644 --- a/src/DemoProject.cpp +++ b/src/DemoProject.cpp @@ -1,10 +1,11 @@ #include -void DemoProject::init(AsyncWebServer* server) { - AdminSettingsService::init(server); +DemoProject::DemoProject(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : AdminSettingsService(server, fs, securityManager, DEMO_SETTINGS_PATH, DEMO_SETTINGS_FILE) { pinMode(BLINK_LED, OUTPUT); } +DemoProject::~DemoProject() {} + void DemoProject::loop() { unsigned delay = MAX_DELAY / 255 * (255 - _blinkSpeed); unsigned long currentMillis = millis(); diff --git a/src/DemoProject.h b/src/DemoProject.h index 0b434a9..0fd09bd 100644 --- a/src/DemoProject.h +++ b/src/DemoProject.h @@ -14,10 +14,9 @@ class DemoProject : public AdminSettingsService { public: - DemoProject(FS* fs, SecurityManager* securityManager) : AdminSettingsService(fs, securityManager, DEMO_SETTINGS_PATH, DEMO_SETTINGS_FILE) {} - ~DemoProject() {} + DemoProject(AsyncWebServer* server, FS* fs, SecurityManager* securityManager); + ~DemoProject(); - void init(AsyncWebServer* server); void loop(); private: diff --git a/src/main.cpp b/src/main.cpp index ea4d706..0447458 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,19 +5,13 @@ #define SERIAL_BAUD_RATE 115200 AsyncWebServer server(80); -ESP8266React framework(&SPIFFS); -DemoProject demoProject = DemoProject(&SPIFFS, framework.getSecurityManager()); +ESP8266React framework(&server, &SPIFFS); +DemoProject demoProject = DemoProject(&server, &SPIFFS, framework.getSecurityManager()); void setup() { // start serial and filesystem Serial.begin(SERIAL_BAUD_RATE); SPIFFS.begin(); - - // set up the framework - framework.init(&server); - - // begin the demo project - demoProject.init(&server); // start the server server.begin();