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:
Rick Watson
2019-11-30 12:34:52 +00:00
parent 69caa841a3
commit 78b9ae101e
20 changed files with 265 additions and 129 deletions

View File

@ -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),

View File

@ -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;

View 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);
}

View 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