Add restart service for esp8266 and esp32
Add restart feature to status screen Upgrade material-ui Add icons to buttons
This commit is contained in:
@ -6,6 +6,7 @@ ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs):
|
||||
_apSettingsService(server, fs, &_securitySettingsService),
|
||||
_ntpSettingsService(server, fs, &_securitySettingsService),
|
||||
_otaSettingsService(server, fs, &_securitySettingsService),
|
||||
_restartService(server, &_securitySettingsService),
|
||||
_authenticationService(server, &_securitySettingsService),
|
||||
_wifiScanner(server, &_securitySettingsService),
|
||||
_wifiStatus(server, &_securitySettingsService),
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <NTPStatus.h>
|
||||
#include <APStatus.h>
|
||||
#include <SystemStatus.h>
|
||||
#include <RestartService.h>
|
||||
|
||||
class ESP8266React {
|
||||
|
||||
@ -46,8 +47,10 @@ class ESP8266React {
|
||||
APSettingsService _apSettingsService;
|
||||
NTPSettingsService _ntpSettingsService;
|
||||
OTASettingsService _otaSettingsService;
|
||||
RestartService _restartService;
|
||||
AuthenticationService _authenticationService;
|
||||
|
||||
|
||||
WiFiScanner _wifiScanner;
|
||||
WiFiStatus _wifiStatus;
|
||||
NTPStatus _ntpStatus;
|
||||
|
14
lib/framework/RestartService.cpp
Normal file
14
lib/framework/RestartService.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include <RestartService.h>
|
||||
|
||||
RestartService::RestartService(AsyncWebServer* server, SecurityManager* securityManager) {
|
||||
server->on(RESTART_SERVICE_PATH, HTTP_POST,
|
||||
securityManager->wrapRequest(std::bind(&RestartService::restart, this, std::placeholders::_1), AuthenticationPredicates::IS_ADMIN)
|
||||
);
|
||||
}
|
||||
|
||||
void RestartService::restart(AsyncWebServerRequest *request) {
|
||||
request->onDisconnect([](){
|
||||
ESP.restart();
|
||||
});
|
||||
request->send(200);
|
||||
}
|
29
lib/framework/RestartService.h
Normal file
29
lib/framework/RestartService.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef RestartService_h
|
||||
#define RestartService_h
|
||||
|
||||
#if defined(ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#elif defined(ESP_PLATFORM)
|
||||
#include <WiFi.h>
|
||||
#include <AsyncTCP.h>
|
||||
#endif
|
||||
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <SecurityManager.h>
|
||||
|
||||
#define RESTART_SERVICE_PATH "/rest/restart"
|
||||
|
||||
class RestartService {
|
||||
|
||||
public:
|
||||
|
||||
RestartService(AsyncWebServer* server, SecurityManager* securityManager);
|
||||
|
||||
private:
|
||||
|
||||
void restart(AsyncWebServerRequest *request);
|
||||
|
||||
};
|
||||
|
||||
#endif // end RestartService_h
|
Reference in New Issue
Block a user