mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
restart dialog
This commit is contained in:
@@ -18,6 +18,7 @@ export const readSystemStatus = () =>
|
||||
// commands
|
||||
export const restart = () => alovaInstance.Post('/rest/restart');
|
||||
export const partition = () => alovaInstance.Post('/rest/partition');
|
||||
export const factoryPartition = () => alovaInstance.Post('/rest/factoryPartition');
|
||||
export const factoryReset = () => alovaInstance.Post('/rest/factoryReset');
|
||||
|
||||
// SystemLog
|
||||
|
||||
@@ -65,6 +65,10 @@ const SystemStatus: FC = () => {
|
||||
immediate: false
|
||||
});
|
||||
|
||||
const { send: factoryPartitionCommand } = useRequest(SystemApi.factoryPartition(), {
|
||||
immediate: false
|
||||
});
|
||||
|
||||
const {
|
||||
data: data,
|
||||
send: loadData,
|
||||
@@ -229,6 +233,21 @@ const SystemStatus: FC = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const factoryPartition = async () => {
|
||||
setProcessing(true);
|
||||
await factoryPartitionCommand()
|
||||
.then(() => {
|
||||
setRestarting(true);
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
toast.error(error.message);
|
||||
})
|
||||
.finally(() => {
|
||||
setConfirmRestart(false);
|
||||
setProcessing(false);
|
||||
});
|
||||
};
|
||||
|
||||
const renderRestartDialog = () => (
|
||||
<Dialog
|
||||
sx={dialogStyle}
|
||||
@@ -247,6 +266,18 @@ const SystemStatus: FC = () => {
|
||||
>
|
||||
{LL.CANCEL()}
|
||||
</Button>
|
||||
{data.has_loader && (
|
||||
<Button
|
||||
startIcon={<PowerSettingsNewIcon />}
|
||||
variant="outlined"
|
||||
onClick={factoryPartition}
|
||||
disabled={processing}
|
||||
color="warning"
|
||||
>
|
||||
EMS-ESP Boot
|
||||
</Button>
|
||||
)}
|
||||
{data.has_partition && (
|
||||
<Button
|
||||
startIcon={<PowerSettingsNewIcon />}
|
||||
variant="outlined"
|
||||
@@ -254,8 +285,9 @@ const SystemStatus: FC = () => {
|
||||
disabled={processing}
|
||||
color="warning"
|
||||
>
|
||||
EMS-ESP Loader
|
||||
Partition
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
startIcon={<PowerSettingsNewIcon />}
|
||||
variant="outlined"
|
||||
|
||||
@@ -24,7 +24,7 @@ export interface HardwareStatus {
|
||||
psram: boolean;
|
||||
psram_size?: number;
|
||||
free_psram?: number;
|
||||
has_loader: boolean;
|
||||
|
||||
free_caps: number;
|
||||
model: string;
|
||||
}
|
||||
@@ -44,6 +44,8 @@ export interface SystemStatus {
|
||||
ap_status: boolean;
|
||||
network_status: NetworkConnectionStatus;
|
||||
wifi_rssi: number;
|
||||
has_loader: boolean;
|
||||
has_partition: boolean;
|
||||
}
|
||||
|
||||
export enum LogLevel {
|
||||
|
||||
@@ -11,6 +11,9 @@ RestartService::RestartService(AsyncWebServer * server, SecurityManager * securi
|
||||
server->on(PARTITION_SERVICE_PATH,
|
||||
HTTP_POST,
|
||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { partition(request); }, AuthenticationPredicates::IS_ADMIN));
|
||||
server->on(FACTORYPARTITION_SERVICE_PATH,
|
||||
HTTP_POST,
|
||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { factory(request); }, AuthenticationPredicates::IS_ADMIN));
|
||||
}
|
||||
|
||||
void RestartService::restartNow() {
|
||||
@@ -26,14 +29,6 @@ void RestartService::restart(AsyncWebServerRequest * request) {
|
||||
}
|
||||
|
||||
void RestartService::partition(AsyncWebServerRequest * request) {
|
||||
const esp_partition_t * factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, nullptr);
|
||||
if (factory_partition) {
|
||||
esp_ota_set_boot_partition(factory_partition);
|
||||
emsesp::EMSESP::system_.store_nvs_values();
|
||||
request->onDisconnect(RestartService::restartNow);
|
||||
request->send(200);
|
||||
return;
|
||||
}
|
||||
const esp_partition_t * ota_partition = esp_ota_get_next_update_partition(nullptr);
|
||||
if (!ota_partition) {
|
||||
request->send(400); // bad request
|
||||
@@ -50,3 +45,15 @@ void RestartService::partition(AsyncWebServerRequest * request) {
|
||||
request->onDisconnect(RestartService::restartNow);
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
void RestartService::factory(AsyncWebServerRequest * request) {
|
||||
const esp_partition_t * factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, nullptr);
|
||||
if (!factory_partition) {
|
||||
request->send(400);
|
||||
return;
|
||||
}
|
||||
esp_ota_set_boot_partition(factory_partition);
|
||||
emsesp::EMSESP::system_.store_nvs_values();
|
||||
request->onDisconnect(RestartService::restartNow);
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#define RESTART_SERVICE_PATH "/rest/restart"
|
||||
#define PARTITION_SERVICE_PATH "/rest/partition"
|
||||
#define FACTORYPARTITION_SERVICE_PATH "/rest/factoryPartition"
|
||||
|
||||
class RestartService {
|
||||
public:
|
||||
@@ -19,6 +20,7 @@ class RestartService {
|
||||
private:
|
||||
void restart(AsyncWebServerRequest * request);
|
||||
void partition(AsyncWebServerRequest * request);
|
||||
void factory(AsyncWebServerRequest * request);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -81,6 +81,17 @@ void WebStatusService::systemStatus(AsyncWebServerRequest * request) {
|
||||
#endif
|
||||
}
|
||||
|
||||
const esp_partition_t * partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, nullptr);
|
||||
root["has_loader"] = partition != NULL;
|
||||
partition = esp_ota_get_next_update_partition(nullptr);
|
||||
if (partition) {
|
||||
uint64_t buffer;
|
||||
esp_partition_read(partition, 0, &buffer, 8);
|
||||
root["has_partition"] = (buffer != 0xFFFFFFFFFFFFFFFF);
|
||||
} else {
|
||||
root["has_partition"] = false;
|
||||
}
|
||||
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
}
|
||||
@@ -127,19 +138,6 @@ void WebStatusService::hardwareStatus(AsyncWebServerRequest * request) {
|
||||
root["free_psram"] = ESP.getFreePsram() / 1024;
|
||||
}
|
||||
|
||||
const esp_partition_t * partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, nullptr);
|
||||
if (partition != NULL) { // factory partition found
|
||||
root["has_loader"] = true;
|
||||
} else { // check for not empty, smaller OTA partition
|
||||
partition = esp_ota_get_next_update_partition(nullptr);
|
||||
if (partition) {
|
||||
uint64_t buffer;
|
||||
esp_partition_read(partition, 0, &buffer, 8);
|
||||
const esp_partition_t * running = esp_ota_get_running_partition();
|
||||
root["has_loader"] = (buffer != 0xFFFFFFFFFFFFFFFF && running->size != partition->size);
|
||||
}
|
||||
}
|
||||
|
||||
root["model"] = EMSESP::system_.getBBQKeesGatewayDetails();
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user