fixes to restart

This commit is contained in:
proddy
2024-09-01 11:07:52 +02:00
parent ccf4362bfc
commit 689a326c89
9 changed files with 31 additions and 15 deletions

View File

@@ -137,7 +137,7 @@ const Customizations = () => {
const doRestart = async () => {
setRestarting(true);
await sendAPI({ device: 'system', cmd: 'restart', id: -1 }).catch(
await sendAPI({ device: 'system', cmd: 'restart', id: 0 }).catch(
(error: Error) => {
toast.error(error.message);
}

View File

@@ -108,7 +108,7 @@ const ApplicationSettings = () => {
const doRestart = async () => {
setRestarting(true);
await sendAPI({ device: 'system', cmd: 'restart', id: -1 }).catch(
await sendAPI({ device: 'system', cmd: 'restart', id: 0 }).catch(
(error: Error) => {
toast.error(error.message);
}

View File

@@ -103,7 +103,7 @@ const DownloadUpload = () => {
const doRestart = async () => {
setRestarting(true);
await sendAPI({ device: 'system', cmd: 'restart', id: -1 }).catch(
await sendAPI({ device: 'system', cmd: 'restart', id: 0 }).catch(
(error: Error) => {
toast.error(error.message);
}

View File

@@ -134,7 +134,7 @@ const NetworkSettings = () => {
const doRestart = async () => {
setRestarting(true);
await sendAPI({ device: 'system', cmd: 'restart', id: -1 }).catch(
await sendAPI({ device: 'system', cmd: 'restart', id: 0 }).catch(
(error: Error) => {
toast.error(error.message);
}

View File

@@ -204,7 +204,7 @@ const SystemStatus = () => {
const doRestart = async () => {
setConfirmRestart(false);
setRestarting(true);
await sendAPI({ device: 'system', cmd: 'restart', id: -1 }).catch(
await sendAPI({ device: 'system', cmd: 'restart', id: 0 }).catch(
(error: Error) => {
toast.error(error.message);
}

View File

@@ -124,7 +124,7 @@ void UploadFileService::uploadComplete(AsyncWebServerRequest * request) {
request->_tempFile.close(); // close the file handle as the upload is now done
AsyncWebServerResponse * response = request->beginResponse(200);
request->send(response);
emsesp::EMSESP::system_.restart_pending(true); // will be handled by the main loop
emsesp::EMSESP::system_.restart_pending(true); // will be handled by the main loop. We use pending for the Web's RestartMonitor
return;
}
@@ -133,7 +133,7 @@ void UploadFileService::uploadComplete(AsyncWebServerRequest * request) {
if (_is_firmware && !request->_tempObject) {
AsyncWebServerResponse * response = request->beginResponse(200);
request->send(response);
emsesp::EMSESP::system_.restart_pending(true); // will be handled by the main loop
emsesp::EMSESP::system_.restart_pending(true); // will be handled by the main loop. We use pending for the Web's RestartMonitor
return;
}

View File

@@ -68,7 +68,7 @@ def on_upload(source, target, env):
"password": password
}
response = requests.post(signon_url, json=username_password, headers=signon_headers, auth=None)
response = requests.post(signon_url, json=username_password, headers=signon_headers)
if response.status_code != 200:
print_fail("Authentication failed (code " + str(response.status_code) + ")")
@@ -116,7 +116,7 @@ def on_upload(source, target, env):
upload_url = f"{emsesp_url}/rest/uploadFile"
response = requests.post(upload_url, data=monitor, headers=post_headers, auth=None)
response = requests.post(upload_url, data=monitor, headers=post_headers)
bar.close()
time.sleep(0.1)
@@ -126,7 +126,22 @@ def on_upload(source, target, env):
if response.status_code != 200:
print_fail("Upload failed (code " + response.status.code + ").")
else:
print_success("Upload successful.")
print_success("Upload successful. Rebooting device.")
restart_headers = {
'Host': host_ip,
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/118.0',
'Accept': '*/*',
'Accept-Language': 'de,en-US;q=0.7,en;q=0.3',
'Accept-Encoding': 'gzip, deflate',
'Referer': f'{emsesp_url}',
'Content-Type': 'application/json',
'Connection': 'keep-alive',
'Authorization': 'Bearer ' + f'{access_token}'
}
restart_url = f"{emsesp_url}/api/system/restart"
response = requests.get(restart_url, headers=restart_headers)
if response.status_code != 200:
print_fail("Restart failed (code " + str(response.status_code) + ")")
print()

View File

@@ -1673,8 +1673,8 @@ void EMSESP::loop() {
// force a query on the EMS devices to fetch latest data at a set interval (1 min)
scheduled_fetch_values();
} else {
emsesp::EMSESP::system_.uploadFirmwareURL(); // start an upload from a URL. This is blocking.
} else if (!system_.uploadFirmwareURL()) { // start an upload from a URL. This is blocking.
system_.upload_status(false); // abort the upload
}
uuid::loop();

View File

@@ -1754,15 +1754,16 @@ bool System::command_format(const char * value, const int8_t id) {
return true;
}
// restart command - perform a hard reset
// restart command - perform a hard reset (system reboot)
bool System::command_restart(const char * value, const int8_t id) {
if (id != 0) {
if (id == 0) {
// if it has an id then it's a web call and we need to queue the restart
// default id is -1 when calling /api/system/restart directly for example
LOG_INFO("Preparing to restart system");
EMSESP::system_.restart_pending(true);
return true;
}
LOG_INFO("Restarting system");
LOG_INFO("Restarting system immediately");
EMSESP::system_.restart_requested(true); // will be handled by the main loop
return true;
}