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,
|
commands->add_command(ShellContext::MAIN,
|
||||||
CommandFlags::ADMIN,
|
CommandFlags::ADMIN,
|
||||||
string_vector{F_(restart)},
|
string_vector{F_(restart)},
|
||||||
string_vector{F_(other_optional)},
|
string_vector{F_(partitionname_optional)},
|
||||||
[](Shell & shell, const std::vector<std::string> & arguments) {
|
[](Shell & shell, const std::vector<std::string> & arguments) {
|
||||||
if (arguments.size()) {
|
if (arguments.size()) {
|
||||||
to_app(shell).system_.system_restart(arguments.front() == "other");
|
to_app(shell).system_.system_restart(arguments.front().c_str());
|
||||||
} else {
|
} else {
|
||||||
to_app(shell).system_.system_restart();
|
to_app(shell).system_.system_restart();
|
||||||
}
|
}
|
||||||
@@ -350,6 +350,43 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
|||||||
to_app(shell).uart_init();
|
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
|
// EMS device commands
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ MAKE_WORD(users)
|
|||||||
MAKE_WORD(publish)
|
MAKE_WORD(publish)
|
||||||
MAKE_WORD(board_profile)
|
MAKE_WORD(board_profile)
|
||||||
MAKE_WORD(setvalue)
|
MAKE_WORD(setvalue)
|
||||||
|
MAKE_WORD(service)
|
||||||
|
|
||||||
// for commands
|
// for commands
|
||||||
MAKE_WORD(call)
|
MAKE_WORD(call)
|
||||||
@@ -140,7 +141,7 @@ MAKE_WORD_CUSTOM(asterisks, "********")
|
|||||||
MAKE_WORD_CUSTOM(n_mandatory, "<n>")
|
MAKE_WORD_CUSTOM(n_mandatory, "<n>")
|
||||||
MAKE_WORD_CUSTOM(sensorid_optional, "[sensor ID]")
|
MAKE_WORD_CUSTOM(sensorid_optional, "[sensor ID]")
|
||||||
MAKE_WORD_CUSTOM(id_optional, "[id|hc]")
|
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(data_optional, "[data]")
|
||||||
MAKE_WORD_CUSTOM(nvs_optional, "[nvs]")
|
MAKE_WORD_CUSTOM(nvs_optional, "[nvs]")
|
||||||
MAKE_WORD_CUSTOM(offset_optional, "[offset]")
|
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(new_password_prompt2, "Retype new password: ")
|
||||||
MAKE_WORD_CUSTOM(password_prompt, "Password: ")
|
MAKE_WORD_CUSTOM(password_prompt, "Password: ")
|
||||||
MAKE_WORD_CUSTOM(unset, "<unset>")
|
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
|
// more common names that don't need translations
|
||||||
MAKE_NOTRANSLATION(1x3min, "1x3min")
|
MAKE_NOTRANSLATION(1x3min, "1x3min")
|
||||||
|
|||||||
@@ -261,31 +261,40 @@ void System::store_nvs_values() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// restart EMS-ESP
|
// restart EMS-ESP
|
||||||
void System::system_restart(const bool other_partition) {
|
void System::system_restart(const char * partitionname) {
|
||||||
if (other_partition) {
|
#ifndef EMSESP_STANDALONE
|
||||||
LOG_INFO("Restarting EMS-ESP to other partition...");
|
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 {
|
} else {
|
||||||
LOG_INFO("Restarting EMS-ESP...");
|
LOG_INFO("Restarting EMS-ESP...");
|
||||||
}
|
}
|
||||||
|
|
||||||
store_nvs_values();
|
store_nvs_values();
|
||||||
Shell::loop_all();
|
Shell::loop_all();
|
||||||
delay(1000); // wait a second
|
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();
|
ESP.restart();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -477,8 +486,8 @@ void System::button_OnDblClick(PButton & b) {
|
|||||||
|
|
||||||
// button long press
|
// button long press
|
||||||
void System::button_OnLongPress(PButton & b) {
|
void System::button_OnLongPress(PButton & b) {
|
||||||
LOG_NOTICE("Button pressed - long press - boot to other partition");
|
LOG_NOTICE("Button pressed - long press - restart other partition");
|
||||||
EMSESP::system_.system_restart(true);
|
EMSESP::system_.system_restart("boot");
|
||||||
}
|
}
|
||||||
|
|
||||||
// button indefinite press
|
// 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
|
// restart command - perform a hard reset
|
||||||
bool System::command_restart(const char * value, const int8_t id) {
|
bool System::command_restart(const char * value, const int8_t id) {
|
||||||
if (value[0] == '1' || strcmp(value, "true") == 0 || strcmp(value, "other") == 0) {
|
if (value != nullptr && value[0] == '\0') {
|
||||||
EMSESP::system_.system_restart(true);
|
EMSESP::system_.system_restart(value);
|
||||||
} else {
|
} else {
|
||||||
EMSESP::system_.system_restart(false);
|
EMSESP::system_.system_restart();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class System {
|
|||||||
std::string reset_reason(uint8_t cpu) const;
|
std::string reset_reason(uint8_t cpu) const;
|
||||||
|
|
||||||
void store_nvs_values();
|
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 format(uuid::console::Shell & shell);
|
||||||
void upload_status(bool in_progress);
|
void upload_status(bool in_progress);
|
||||||
bool upload_status();
|
bool upload_status();
|
||||||
|
|||||||
Reference in New Issue
Block a user