mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
add restart to factory partition (if there is one)
This commit is contained in:
@@ -12,6 +12,10 @@ export function restart(): AxiosPromise<void> {
|
|||||||
return AXIOS.post('/restart');
|
return AXIOS.post('/restart');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function partition(): AxiosPromise<void> {
|
||||||
|
return AXIOS.post('/partition');
|
||||||
|
}
|
||||||
|
|
||||||
export function factoryReset(): AxiosPromise<void> {
|
export function factoryReset(): AxiosPromise<void> {
|
||||||
return AXIOS.post('/factoryReset');
|
return AXIOS.post('/factoryReset');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,19 @@ const SystemStatusForm: FC = () => {
|
|||||||
setProcessing(true);
|
setProcessing(true);
|
||||||
try {
|
try {
|
||||||
await SystemApi.restart();
|
await SystemApi.restart();
|
||||||
enqueueSnackbar(LL.APPLICATION_RESTARTING(), { variant: 'info' });
|
setRestarting(true);
|
||||||
|
} catch (error) {
|
||||||
|
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' });
|
||||||
|
} finally {
|
||||||
|
setConfirmRestart(false);
|
||||||
|
setProcessing(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const partition = async () => {
|
||||||
|
setProcessing(true);
|
||||||
|
try {
|
||||||
|
await SystemApi.partition();
|
||||||
setRestarting(true);
|
setRestarting(true);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' });
|
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_LOADING()), { variant: 'error' });
|
||||||
@@ -121,6 +133,17 @@ const SystemStatusForm: FC = () => {
|
|||||||
>
|
>
|
||||||
{LL.RESTART()}
|
{LL.RESTART()}
|
||||||
</Button>
|
</Button>
|
||||||
|
{data?.has_loader && (
|
||||||
|
<Button
|
||||||
|
startIcon={<PowerSettingsNewIcon />}
|
||||||
|
variant="outlined"
|
||||||
|
onClick={partition}
|
||||||
|
disabled={processing}
|
||||||
|
color="primary"
|
||||||
|
>
|
||||||
|
EMS-ESP-Loader
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import * as EMSESP from './api';
|
|||||||
import { Settings, BOARD_PROFILES } from './types';
|
import { Settings, BOARD_PROFILES } from './types';
|
||||||
|
|
||||||
import { useI18nContext } from '../i18n/i18n-react';
|
import { useI18nContext } from '../i18n/i18n-react';
|
||||||
|
import RestartMonitor from '../framework/system/RestartMonitor';
|
||||||
|
|
||||||
export function boardProfileSelectItems() {
|
export function boardProfileSelectItems() {
|
||||||
return Object.keys(BOARD_PROFILES).map((code) => (
|
return Object.keys(BOARD_PROFILES).map((code) => (
|
||||||
@@ -39,6 +40,7 @@ const SettingsApplication: FC = () => {
|
|||||||
read: EMSESP.readSettings,
|
read: EMSESP.readSettings,
|
||||||
update: EMSESP.writeSettings
|
update: EMSESP.writeSettings
|
||||||
});
|
});
|
||||||
|
const [restarting, setRestarting] = useState<boolean>();
|
||||||
|
|
||||||
const { LL } = useI18nContext();
|
const { LL } = useI18nContext();
|
||||||
|
|
||||||
@@ -106,7 +108,7 @@ const SettingsApplication: FC = () => {
|
|||||||
validateAndSubmit();
|
validateAndSubmit();
|
||||||
try {
|
try {
|
||||||
await EMSESP.restart();
|
await EMSESP.restart();
|
||||||
enqueueSnackbar(LL.APPLICATION_RESTARTING(), { variant: 'info' });
|
setRestarting(true);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
|
enqueueSnackbar(extractErrorMessage(error, LL.PROBLEM_UPDATING()), { variant: 'error' });
|
||||||
}
|
}
|
||||||
@@ -617,7 +619,7 @@ const SettingsApplication: FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<SectionContent title={LL.APPLICATION_SETTINGS()} titleGutter>
|
<SectionContent title={LL.APPLICATION_SETTINGS()} titleGutter>
|
||||||
{content()}
|
{restarting ? <RestartMonitor /> : content()}
|
||||||
</SectionContent>
|
</SectionContent>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export interface SystemStatus {
|
|||||||
free_mem: number;
|
free_mem: number;
|
||||||
psram_size?: number;
|
psram_size?: number;
|
||||||
free_psram?: number;
|
free_psram?: number;
|
||||||
|
has_loader: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface OTASettings {
|
export interface OTASettings {
|
||||||
|
|||||||
@@ -1,12 +1,27 @@
|
|||||||
#include <RestartService.h>
|
#include <RestartService.h>
|
||||||
|
#include <esp_ota_ops.h>
|
||||||
|
|
||||||
using namespace std::placeholders; // for `_1` etc
|
using namespace std::placeholders; // for `_1` etc
|
||||||
|
|
||||||
RestartService::RestartService(AsyncWebServer * server, SecurityManager * securityManager) {
|
RestartService::RestartService(AsyncWebServer * server, SecurityManager * securityManager) {
|
||||||
server->on(RESTART_SERVICE_PATH, HTTP_POST, securityManager->wrapRequest(std::bind(&RestartService::restart, this, _1), AuthenticationPredicates::IS_ADMIN));
|
server->on(RESTART_SERVICE_PATH, HTTP_POST, securityManager->wrapRequest(std::bind(&RestartService::restart, this, _1), AuthenticationPredicates::IS_ADMIN));
|
||||||
|
server->on(PARTITION_SERVICE_PATH,
|
||||||
|
HTTP_POST,
|
||||||
|
securityManager->wrapRequest(std::bind(&RestartService::partition, this, _1), AuthenticationPredicates::IS_ADMIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RestartService::restart(AsyncWebServerRequest * request) {
|
void RestartService::restart(AsyncWebServerRequest * request) {
|
||||||
request->onDisconnect(RestartService::restartNow);
|
request->onDisconnect(RestartService::restartNow);
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RestartService::partition(AsyncWebServerRequest * request) {
|
||||||
|
const esp_partition_t * factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
|
||||||
|
if (!factory_partition) {
|
||||||
|
request->send(400); // bad request
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
esp_ota_set_boot_partition(factory_partition);
|
||||||
|
request->onDisconnect(RestartService::restartNow);
|
||||||
|
request->send(200);
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <SecurityManager.h>
|
#include <SecurityManager.h>
|
||||||
|
|
||||||
#define RESTART_SERVICE_PATH "/rest/restart"
|
#define RESTART_SERVICE_PATH "/rest/restart"
|
||||||
|
#define PARTITION_SERVICE_PATH "/rest/partition"
|
||||||
|
|
||||||
class RestartService {
|
class RestartService {
|
||||||
public:
|
public:
|
||||||
@@ -21,6 +22,7 @@ class RestartService {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void restart(AsyncWebServerRequest * request);
|
void restart(AsyncWebServerRequest * request);
|
||||||
|
void partition(AsyncWebServerRequest * request);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user