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
|
// commands
|
||||||
export const restart = () => alovaInstance.Post('/rest/restart');
|
export const restart = () => alovaInstance.Post('/rest/restart');
|
||||||
export const partition = () => alovaInstance.Post('/rest/partition');
|
export const partition = () => alovaInstance.Post('/rest/partition');
|
||||||
|
export const factoryPartition = () => alovaInstance.Post('/rest/factoryPartition');
|
||||||
export const factoryReset = () => alovaInstance.Post('/rest/factoryReset');
|
export const factoryReset = () => alovaInstance.Post('/rest/factoryReset');
|
||||||
|
|
||||||
// SystemLog
|
// SystemLog
|
||||||
|
|||||||
@@ -65,6 +65,10 @@ const SystemStatus: FC = () => {
|
|||||||
immediate: false
|
immediate: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { send: factoryPartitionCommand } = useRequest(SystemApi.factoryPartition(), {
|
||||||
|
immediate: false
|
||||||
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: data,
|
data: data,
|
||||||
send: loadData,
|
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 = () => (
|
const renderRestartDialog = () => (
|
||||||
<Dialog
|
<Dialog
|
||||||
sx={dialogStyle}
|
sx={dialogStyle}
|
||||||
@@ -247,15 +266,28 @@ const SystemStatus: FC = () => {
|
|||||||
>
|
>
|
||||||
{LL.CANCEL()}
|
{LL.CANCEL()}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
{data.has_loader && (
|
||||||
startIcon={<PowerSettingsNewIcon />}
|
<Button
|
||||||
variant="outlined"
|
startIcon={<PowerSettingsNewIcon />}
|
||||||
onClick={partition}
|
variant="outlined"
|
||||||
disabled={processing}
|
onClick={factoryPartition}
|
||||||
color="warning"
|
disabled={processing}
|
||||||
>
|
color="warning"
|
||||||
EMS-ESP Loader
|
>
|
||||||
</Button>
|
EMS-ESP Boot
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{data.has_partition && (
|
||||||
|
<Button
|
||||||
|
startIcon={<PowerSettingsNewIcon />}
|
||||||
|
variant="outlined"
|
||||||
|
onClick={partition}
|
||||||
|
disabled={processing}
|
||||||
|
color="warning"
|
||||||
|
>
|
||||||
|
Partition
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
startIcon={<PowerSettingsNewIcon />}
|
startIcon={<PowerSettingsNewIcon />}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export interface HardwareStatus {
|
|||||||
psram: boolean;
|
psram: boolean;
|
||||||
psram_size?: number;
|
psram_size?: number;
|
||||||
free_psram?: number;
|
free_psram?: number;
|
||||||
has_loader: boolean;
|
|
||||||
free_caps: number;
|
free_caps: number;
|
||||||
model: string;
|
model: string;
|
||||||
}
|
}
|
||||||
@@ -44,6 +44,8 @@ export interface SystemStatus {
|
|||||||
ap_status: boolean;
|
ap_status: boolean;
|
||||||
network_status: NetworkConnectionStatus;
|
network_status: NetworkConnectionStatus;
|
||||||
wifi_rssi: number;
|
wifi_rssi: number;
|
||||||
|
has_loader: boolean;
|
||||||
|
has_partition: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum LogLevel {
|
export enum LogLevel {
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ RestartService::RestartService(AsyncWebServer * server, SecurityManager * securi
|
|||||||
server->on(PARTITION_SERVICE_PATH,
|
server->on(PARTITION_SERVICE_PATH,
|
||||||
HTTP_POST,
|
HTTP_POST,
|
||||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { partition(request); }, AuthenticationPredicates::IS_ADMIN));
|
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() {
|
void RestartService::restartNow() {
|
||||||
@@ -26,14 +29,6 @@ void RestartService::restart(AsyncWebServerRequest * request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RestartService::partition(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);
|
const esp_partition_t * ota_partition = esp_ota_get_next_update_partition(nullptr);
|
||||||
if (!ota_partition) {
|
if (!ota_partition) {
|
||||||
request->send(400); // bad request
|
request->send(400); // bad request
|
||||||
@@ -50,3 +45,15 @@ void RestartService::partition(AsyncWebServerRequest * request) {
|
|||||||
request->onDisconnect(RestartService::restartNow);
|
request->onDisconnect(RestartService::restartNow);
|
||||||
request->send(200);
|
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 RESTART_SERVICE_PATH "/rest/restart"
|
||||||
#define PARTITION_SERVICE_PATH "/rest/partition"
|
#define PARTITION_SERVICE_PATH "/rest/partition"
|
||||||
|
#define FACTORYPARTITION_SERVICE_PATH "/rest/factoryPartition"
|
||||||
|
|
||||||
class RestartService {
|
class RestartService {
|
||||||
public:
|
public:
|
||||||
@@ -19,6 +20,7 @@ class RestartService {
|
|||||||
private:
|
private:
|
||||||
void restart(AsyncWebServerRequest * request);
|
void restart(AsyncWebServerRequest * request);
|
||||||
void partition(AsyncWebServerRequest * request);
|
void partition(AsyncWebServerRequest * request);
|
||||||
|
void factory(AsyncWebServerRequest * request);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -81,6 +81,17 @@ void WebStatusService::systemStatus(AsyncWebServerRequest * request) {
|
|||||||
#endif
|
#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();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
@@ -127,19 +138,6 @@ void WebStatusService::hardwareStatus(AsyncWebServerRequest * request) {
|
|||||||
root["free_psram"] = ESP.getFreePsram() / 1024;
|
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();
|
root["model"] = EMSESP::system_.getBBQKeesGatewayDetails();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user