2019-12-01 08:28:40 +00:00
|
|
|
#include <RestartService.h>
|
|
|
|
|
|
|
|
RestartService::RestartService(AsyncWebServer* server, SecurityManager* securityManager) {
|
2019-12-03 23:16:06 +00:00
|
|
|
server->on(RESTART_SERVICE_PATH,
|
|
|
|
HTTP_POST,
|
|
|
|
securityManager->wrapRequest(std::bind(&RestartService::restart, this, std::placeholders::_1),
|
|
|
|
AuthenticationPredicates::IS_ADMIN));
|
2019-12-01 08:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RestartService::restart(AsyncWebServerRequest* request) {
|
|
|
|
request->onDisconnect([]() {
|
2019-12-24 11:19:19 +00:00
|
|
|
#ifdef ESP32
|
2019-12-01 08:28:40 +00:00
|
|
|
ESP.restart();
|
2019-12-24 11:19:19 +00:00
|
|
|
#elif defined(ESP8266)
|
|
|
|
ESP.reset();
|
2019-12-01 08:28:40 +00:00
|
|
|
#endif
|
|
|
|
});
|
|
|
|
request->send(200);
|
|
|
|
}
|