mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
restart option partitionname, console-command set service
This commit is contained in:
@@ -201,10 +201,10 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
||||
commands->add_command(ShellContext::MAIN,
|
||||
CommandFlags::ADMIN,
|
||||
string_vector{F_(restart)},
|
||||
string_vector{F_(other_optional)},
|
||||
string_vector{F_(partitionname_optional)},
|
||||
[](Shell & shell, const std::vector<std::string> & arguments) {
|
||||
if (arguments.size()) {
|
||||
to_app(shell).system_.system_restart(arguments.front() == "other");
|
||||
to_app(shell).system_.system_restart(arguments.front().c_str());
|
||||
} else {
|
||||
to_app(shell).system_.system_restart();
|
||||
}
|
||||
@@ -350,6 +350,43 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
||||
to_app(shell).uart_init();
|
||||
});
|
||||
|
||||
commands->add_command(ShellContext::MAIN,
|
||||
CommandFlags::ADMIN,
|
||||
string_vector{F_(set), F_(service)},
|
||||
string_vector{F_(service_mandatory), F_(enable_mandatory)},
|
||||
[](Shell & shell, const std::vector<std::string> & arguments) {
|
||||
if (arguments.back() == "enable" || arguments.back() == "disable") {
|
||||
bool enable = arguments.back() == "enable";
|
||||
if (arguments.front() == "mqtt") {
|
||||
to_app(shell).esp8266React.getMqttSettingsService()->update([&](MqttSettings & Settings) {
|
||||
Settings.enabled = enable;
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
} else if (arguments.front() == "ota") {
|
||||
to_app(shell).esp8266React.getOTASettingsService()->update([&](OTASettings & Settings) {
|
||||
Settings.enabled = enable;
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
} else if (arguments.front() == "ntp") {
|
||||
to_app(shell).esp8266React.getNTPSettingsService()->update([&](NTPSettings & Settings) {
|
||||
Settings.enabled = enable;
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
} else if (arguments.front() == "ap") {
|
||||
to_app(shell).esp8266React.getAPSettingsService()->update([&](APSettings & Settings) {
|
||||
Settings.provisionMode = enable ? 0 : 2;
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
} else {
|
||||
shell.printfln("unknown service: %s", arguments.front().c_str());
|
||||
return;
|
||||
}
|
||||
shell.printfln("service '%s' %sd", arguments.front().c_str(), arguments.back().c_str());
|
||||
} else {
|
||||
shell.println("Must be `enable` or `disable`");
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// EMS device commands
|
||||
//
|
||||
|
||||
@@ -65,6 +65,7 @@ MAKE_WORD(users)
|
||||
MAKE_WORD(publish)
|
||||
MAKE_WORD(board_profile)
|
||||
MAKE_WORD(setvalue)
|
||||
MAKE_WORD(service)
|
||||
|
||||
// for commands
|
||||
MAKE_WORD(call)
|
||||
@@ -140,7 +141,7 @@ MAKE_WORD_CUSTOM(asterisks, "********")
|
||||
MAKE_WORD_CUSTOM(n_mandatory, "<n>")
|
||||
MAKE_WORD_CUSTOM(sensorid_optional, "[sensor ID]")
|
||||
MAKE_WORD_CUSTOM(id_optional, "[id|hc]")
|
||||
MAKE_WORD_CUSTOM(other_optional, "[other]")
|
||||
MAKE_WORD_CUSTOM(partitionname_optional, "[partitionsname]")
|
||||
MAKE_WORD_CUSTOM(data_optional, "[data]")
|
||||
MAKE_WORD_CUSTOM(nvs_optional, "[nvs]")
|
||||
MAKE_WORD_CUSTOM(offset_optional, "[offset]")
|
||||
@@ -156,6 +157,8 @@ MAKE_WORD_CUSTOM(new_password_prompt1, "Enter new password: ")
|
||||
MAKE_WORD_CUSTOM(new_password_prompt2, "Retype new password: ")
|
||||
MAKE_WORD_CUSTOM(password_prompt, "Password: ")
|
||||
MAKE_WORD_CUSTOM(unset, "<unset>")
|
||||
MAKE_WORD_CUSTOM(enable_mandatory, "<enable | disable>")
|
||||
MAKE_WORD_CUSTOM(service_mandatory, "<ota | ap | mqtt | ntp>")
|
||||
|
||||
// more common names that don't need translations
|
||||
MAKE_NOTRANSLATION(1x3min, "1x3min")
|
||||
|
||||
@@ -261,31 +261,40 @@ void System::store_nvs_values() {
|
||||
}
|
||||
|
||||
// restart EMS-ESP
|
||||
void System::system_restart(const bool other_partition) {
|
||||
if (other_partition) {
|
||||
LOG_INFO("Restarting EMS-ESP to other partition...");
|
||||
void System::system_restart(const char * partitionname) {
|
||||
#ifndef EMSESP_STANDALONE
|
||||
if (partitionname != nullptr) {
|
||||
const esp_partition_t * partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
|
||||
if (partition && strcmp(partition->label, partitionname) == 0) {
|
||||
esp_ota_set_boot_partition(partition);
|
||||
} else if (strcmp(esp_ota_get_running_partition()->label, partitionname) != 0) {
|
||||
partition = esp_ota_get_next_update_partition(NULL);
|
||||
if (!partition) {
|
||||
LOG_ERROR("Partition '%s' not found", partitionname);
|
||||
return;
|
||||
}
|
||||
if (strcmp(partition->label, partitionname) != 0 && strcmp(partitionname, "boot") != 0) {
|
||||
partition = esp_ota_get_next_update_partition(partition);
|
||||
if (!partition || strcmp(partition->label, partitionname)) {
|
||||
LOG_ERROR("Partition '%s' not found", partitionname);
|
||||
return;
|
||||
}
|
||||
}
|
||||
uint64_t buffer;
|
||||
esp_partition_read(partition, 0, &buffer, 8);
|
||||
if (buffer == 0xFFFFFFFFFFFFFFFF) { // partition empty
|
||||
LOG_ERROR("Partition '%s' is empty, not bootable", partition->label);
|
||||
return;
|
||||
}
|
||||
esp_ota_set_boot_partition(partition);
|
||||
}
|
||||
LOG_INFO("Restarting EMS-ESP from partition '%s'", partitionname);
|
||||
} else {
|
||||
LOG_INFO("Restarting EMS-ESP...");
|
||||
}
|
||||
|
||||
store_nvs_values();
|
||||
Shell::loop_all();
|
||||
delay(1000); // wait a second
|
||||
#ifndef EMSESP_STANDALONE
|
||||
if (other_partition) {
|
||||
// check for factory partiton
|
||||
const esp_partition_t * partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
|
||||
if (!partition) {
|
||||
partition = esp_ota_get_next_update_partition(NULL);
|
||||
}
|
||||
if (partition) {
|
||||
uint64_t buffer;
|
||||
esp_partition_read(partition, 0, &buffer, 8);
|
||||
if (buffer != 0xFFFFFFFFFFFFFFFF) { // partition not empty
|
||||
esp_ota_set_boot_partition(partition);
|
||||
}
|
||||
}
|
||||
}
|
||||
ESP.restart();
|
||||
#endif
|
||||
}
|
||||
@@ -477,8 +486,8 @@ void System::button_OnDblClick(PButton & b) {
|
||||
|
||||
// button long press
|
||||
void System::button_OnLongPress(PButton & b) {
|
||||
LOG_NOTICE("Button pressed - long press - boot to other partition");
|
||||
EMSESP::system_.system_restart(true);
|
||||
LOG_NOTICE("Button pressed - long press - restart other partition");
|
||||
EMSESP::system_.system_restart("boot");
|
||||
}
|
||||
|
||||
// button indefinite press
|
||||
@@ -1533,10 +1542,10 @@ bool System::load_board_profile(std::vector<int8_t> & data, const std::string &
|
||||
|
||||
// restart command - perform a hard reset
|
||||
bool System::command_restart(const char * value, const int8_t id) {
|
||||
if (value[0] == '1' || strcmp(value, "true") == 0 || strcmp(value, "other") == 0) {
|
||||
EMSESP::system_.system_restart(true);
|
||||
if (value != nullptr && value[0] == '\0') {
|
||||
EMSESP::system_.system_restart(value);
|
||||
} else {
|
||||
EMSESP::system_.system_restart(false);
|
||||
EMSESP::system_.system_restart();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class System {
|
||||
std::string reset_reason(uint8_t cpu) const;
|
||||
|
||||
void store_nvs_values();
|
||||
void system_restart(const bool other_partition = false);
|
||||
void system_restart(const char * partition = nullptr);
|
||||
void format(uuid::console::Shell & shell);
|
||||
void upload_status(bool in_progress);
|
||||
bool upload_status();
|
||||
|
||||
Reference in New Issue
Block a user