Use ESP.reset() rather than ESP.restart() - due to exceptions encountered on esp8266

This commit is contained in:
Rick Watson
2019-11-30 12:54:57 +00:00
parent 78b9ae101e
commit a840aba878
8 changed files with 70 additions and 70 deletions

View File

@ -6,7 +6,7 @@ ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs):
_apSettingsService(server, fs, &_securitySettingsService),
_ntpSettingsService(server, fs, &_securitySettingsService),
_otaSettingsService(server, fs, &_securitySettingsService),
_restartService(server, &_securitySettingsService),
_ResetService(server, &_securitySettingsService),
_authenticationService(server, &_securitySettingsService),
_wifiScanner(server, &_securitySettingsService),
_wifiStatus(server, &_securitySettingsService),

View File

@ -24,7 +24,7 @@
#include <NTPStatus.h>
#include <APStatus.h>
#include <SystemStatus.h>
#include <RestartService.h>
#include <ResetService.h>
class ESP8266React {
@ -47,7 +47,7 @@ class ESP8266React {
APSettingsService _apSettingsService;
NTPSettingsService _ntpSettingsService;
OTASettingsService _otaSettingsService;
RestartService _restartService;
ResetService _ResetService;
AuthenticationService _authenticationService;

View File

@ -0,0 +1,14 @@
#include <ResetService.h>
ResetService::ResetService(AsyncWebServer* server, SecurityManager* securityManager) {
server->on(RESET_SERVICE_PATH, HTTP_POST,
securityManager->wrapRequest(std::bind(&ResetService::reset, this, std::placeholders::_1), AuthenticationPredicates::IS_ADMIN)
);
}
void ResetService::reset(AsyncWebServerRequest *request) {
request->onDisconnect([](){
ESP.reset();
});
request->send(200);
}

View File

@ -0,0 +1,29 @@
#ifndef ResetService_h
#define ResetService_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 RESET_SERVICE_PATH "/rest/reset"
class ResetService {
public:
ResetService(AsyncWebServer* server, SecurityManager* securityManager);
private:
void reset(AsyncWebServerRequest *request);
};
#endif // end ResetService_h

View File

@ -1,14 +0,0 @@
#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

@ -1,29 +0,0 @@
#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