diff --git a/interface/src/constants/Endpoints.js b/interface/src/constants/Endpoints.js index 2fc772d..fc6b7cc 100644 --- a/interface/src/constants/Endpoints.js +++ b/interface/src/constants/Endpoints.js @@ -13,4 +13,4 @@ export const SYSTEM_STATUS_ENDPOINT = ENDPOINT_ROOT + "systemStatus"; export const SIGN_IN_ENDPOINT = ENDPOINT_ROOT + "signIn"; export const VERIFY_AUTHORIZATION_ENDPOINT = ENDPOINT_ROOT + "verifyAuthorization"; export const SECURITY_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "securitySettings"; -export const RESTART_ENDPOINT = ENDPOINT_ROOT + "restart"; +export const RESET_ENDPOINT = ENDPOINT_ROOT + "reset"; diff --git a/interface/src/containers/SystemStatus.js b/interface/src/containers/SystemStatus.js index b2ae237..126ee37 100644 --- a/interface/src/containers/SystemStatus.js +++ b/interface/src/containers/SystemStatus.js @@ -22,7 +22,7 @@ import DataUsageIcon from '@material-ui/icons/DataUsage'; import AutorenewIcon from '@material-ui/icons/Autorenew'; import RefreshIcon from '@material-ui/icons/Refresh'; -import { SYSTEM_STATUS_ENDPOINT, RESTART_ENDPOINT } from '../constants/Endpoints'; +import { SYSTEM_STATUS_ENDPOINT, RESET_ENDPOINT } from '../constants/Endpoints'; import { restComponent } from '../components/RestComponent'; import LoadingNotification from '../components/LoadingNotification'; import SectionContent from '../components/SectionContent'; @@ -42,7 +42,7 @@ class SystemStatus extends Component { super(props); this.state = { - confirmRestart: false, + confirmReset: false, processing: false } } @@ -112,53 +112,53 @@ class SystemStatus extends Component { - ); } - onRestart = () => { - this.setState({ confirmRestart: true }); + onReset = () => { + this.setState({ confirmReset: true }); } - onRestartRejected = () => { - this.setState({ confirmRestart: false }); + onResetRejected = () => { + this.setState({ confirmReset: false }); } - onRestartConfirmed = () => { + onResetConfirmed = () => { this.setState({ processing: true }); - redirectingAuthorizedFetch(RESTART_ENDPOINT, { method: 'POST' }) + redirectingAuthorizedFetch(RESET_ENDPOINT, { method: 'POST' }) .then(response => { if (response.status === 200) { - this.props.enqueueSnackbar("Device is restarting", { variant: 'info' }); - this.setState({ processing: false, confirmRestart: false }); + this.props.enqueueSnackbar("Device is reseting", { variant: 'info' }); + this.setState({ processing: false, confirmReset: false }); } else { throw Error("Invalid status code: " + response.status); } }) .catch(error => { - this.props.enqueueSnackbar(error.message || "Problem restarting device", { variant: 'error' }); - this.setState({ processing: false, confirmRestart: false }); + this.props.enqueueSnackbar(error.message || "Problem resetting device", { variant: 'error' }); + this.setState({ processing: false, confirmReset: false }); }); } - renderRestartDialog() { + renderResetDialog() { return ( - Confirm Restart + Confirm Reset - Are you sure you want to restart the device? + Are you sure you want to reset the device? - - @@ -178,7 +178,7 @@ class SystemStatus extends Component { () => this.renderSystemStatus(data, classes) } /> - {this.renderRestartDialog()} + {this.renderResetDialog()} ) } diff --git a/lib/framework/ESP8266React.cpp b/lib/framework/ESP8266React.cpp index fefa68e..e2cdcb8 100644 --- a/lib/framework/ESP8266React.cpp +++ b/lib/framework/ESP8266React.cpp @@ -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), diff --git a/lib/framework/ESP8266React.h b/lib/framework/ESP8266React.h index 1232345..75e33a8 100644 --- a/lib/framework/ESP8266React.h +++ b/lib/framework/ESP8266React.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include class ESP8266React { @@ -47,7 +47,7 @@ class ESP8266React { APSettingsService _apSettingsService; NTPSettingsService _ntpSettingsService; OTASettingsService _otaSettingsService; - RestartService _restartService; + ResetService _ResetService; AuthenticationService _authenticationService; diff --git a/lib/framework/ResetService.cpp b/lib/framework/ResetService.cpp new file mode 100644 index 0000000..dcf8f6f --- /dev/null +++ b/lib/framework/ResetService.cpp @@ -0,0 +1,14 @@ +#include + +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); +} diff --git a/lib/framework/ResetService.h b/lib/framework/ResetService.h new file mode 100644 index 0000000..ab9b729 --- /dev/null +++ b/lib/framework/ResetService.h @@ -0,0 +1,29 @@ +#ifndef ResetService_h +#define ResetService_h + +#if defined(ESP8266) + #include + #include +#elif defined(ESP_PLATFORM) + #include + #include +#endif + +#include +#include + +#define RESET_SERVICE_PATH "/rest/reset" + +class ResetService { + + public: + + ResetService(AsyncWebServer* server, SecurityManager* securityManager); + + private: + + void reset(AsyncWebServerRequest *request); + +}; + +#endif // end ResetService_h \ No newline at end of file diff --git a/lib/framework/RestartService.cpp b/lib/framework/RestartService.cpp deleted file mode 100644 index 3819f46..0000000 --- a/lib/framework/RestartService.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include - -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); -} diff --git a/lib/framework/RestartService.h b/lib/framework/RestartService.h deleted file mode 100644 index 8bcfec3..0000000 --- a/lib/framework/RestartService.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef RestartService_h -#define RestartService_h - -#if defined(ESP8266) - #include - #include -#elif defined(ESP_PLATFORM) - #include - #include -#endif - -#include -#include - -#define RESTART_SERVICE_PATH "/rest/restart" - -class RestartService { - - public: - - RestartService(AsyncWebServer* server, SecurityManager* securityManager); - - private: - - void restart(AsyncWebServerRequest *request); - -}; - -#endif // end RestartService_h \ No newline at end of file