diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index dfc3819ab..dab01489b 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -20,8 +20,10 @@ - mixer MM100 telegram 0x2CC [#1554](https://github.com/emsesp/EMS-ESP32/issues/1554) - boiler hpSetDiffPressure [#1563](https://github.com/emsesp/EMS-ESP32/issues/1563) - custom variables [#1423](https://github.com/emsesp/EMS-ESP32/issues/1423) -- weather compensation [#1642](https://github.com/emsesp/EMS-ESP32/issues/1442) +- weather compensation [#1642](https://github.com/emsesp/EMS-ESP32/issues/1642) - env and partitions for DevKitC-1-N32R8 [#1635](https://github.com/emsesp/EMS-ESP32/discussions/1635) +- command `restart partitionname` and button long press to start with other partition [#1657](https://github.com/emsesp/EMS-ESP32/issues/1657) +- command `set service ` [#1663](https://github.com/emsesp/EMS-ESP32/issues/1663) ## Fixed @@ -45,4 +47,5 @@ - Length of mqtt Broker adress [#1619](https://github.com/emsesp/EMS-ESP32/issues/1619) - C++ optimizations - see - Send MQTT heartbeat immediately after connection [#1628](https://github.com/emsesp/EMS-ESP32/issues/1628) -- 16MB partitions with second nvs, larger FS, Coredump +- 16MB partitions with second nvs, larger FS, Coredump, optional factory partition +- stop fetching empty telegrams after 5 min diff --git a/esp32_partition_16M_factory.csv b/esp32_partition_16M_factory.csv new file mode 100644 index 000000000..7ec71a0be --- /dev/null +++ b/esp32_partition_16M_factory.csv @@ -0,0 +1,9 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x005000, +otadata, data, ota, , 0x002000, +boot, app, factory, , 0x280000, +app0, app, ota_0, , 0x590000, +app1, app, ota_1, , 0x590000, +nvs1, data, nvs, , 0x040000, +spiffs, data, spiffs, , 0x200000, +coredump, data, coredump,, 0x010000, \ No newline at end of file diff --git a/src/console.cpp b/src/console.cpp index bdb466a88..9c523f701 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -198,9 +198,17 @@ static void setup_commands(std::shared_ptr & commands) { }); }); - commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, string_vector{F_(restart)}, [](Shell & shell, const std::vector & arguments) { - to_app(shell).system_.system_restart(); - }); + commands->add_command(ShellContext::MAIN, + CommandFlags::ADMIN, + string_vector{F_(restart)}, + string_vector{F_(partitionname_optional)}, + [](Shell & shell, const std::vector & arguments) { + if (arguments.size()) { + to_app(shell).system_.system_restart(arguments.front().c_str()); + } else { + to_app(shell).system_.system_restart(); + } + }); commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, @@ -344,6 +352,43 @@ static void setup_commands(std::shared_ptr & 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 & 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 // diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 06254b663..7266d2364 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -1819,8 +1819,11 @@ bool EMSdevice::handle_telegram(std::shared_ptr telegram) { #if defined(EMSESP_DEBUG) EMSESP::logger().debug("This telegram (%s) is not recognized by the EMS bus", tf.telegram_type_name_); #endif - // removing fetch causes issue: https://github.com/emsesp/EMS-ESP32/issues/1420 - // tf.fetch_ = false; + // removing fetch after start causes issue: https://github.com/emsesp/EMS-ESP32/issues/1420 + // continue retry the first 5 minutes, then disable (added 15.3.2024) + if (uuid::get_uptime_sec() > 600) { + tf.fetch_ = false; + } return false; } if (telegram->message_length > 0) { diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 08271d021..4ad563dea 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -18,6 +18,10 @@ #include "emsesp.h" +#ifndef EMSESP_STANDALONE +#include "esp_ota_ops.h" +#endif + static_assert(uuid::thread_safe, "uuid-common must be thread-safe"); static_assert(uuid::log::thread_safe, "uuid-log must be thread-safe"); static_assert(uuid::console::thread_safe, "uuid-console must be thread-safe"); @@ -1488,9 +1492,14 @@ void EMSESP::start() { esp8266React.begin(); // loads core system services settings (network, mqtt, ap, ntp etc) - nvs_.begin("ems-esp", false, "nvs"); - + if (!nvs_.begin("ems-esp", false, "nvs1")) { // try bigger nvs partition on 16M flash first + nvs_.begin("ems-esp", false, "nvs"); // fallback to small nvs + } +#ifndef EMSESP_STANDALONE + LOG_INFO("Starting EMS-ESP version %s from partition %s", EMSESP_APP_VERSION, esp_ota_get_running_partition()->label); // welcome message +#else LOG_INFO("Starting EMS-ESP version %s", EMSESP_APP_VERSION); // welcome message +#endif LOG_DEBUG("System is running in Debug mode"); LOG_INFO("Last system reset reason Core0: %s, Core1: %s", system_.reset_reason(0).c_str(), system_.reset_reason(1).c_str()); diff --git a/src/locale_common.h b/src/locale_common.h index 59e965ad8..522704668 100644 --- a/src/locale_common.h +++ b/src/locale_common.h @@ -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,6 +141,7 @@ MAKE_WORD_CUSTOM(asterisks, "********") MAKE_WORD_CUSTOM(n_mandatory, "") MAKE_WORD_CUSTOM(sensorid_optional, "[sensor ID]") MAKE_WORD_CUSTOM(id_optional, "[id|hc]") +MAKE_WORD_CUSTOM(partitionname_optional, "[partitionsname]") MAKE_WORD_CUSTOM(data_optional, "[data]") MAKE_WORD_CUSTOM(nvs_optional, "[nvs]") MAKE_WORD_CUSTOM(offset_optional, "[offset]") @@ -155,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, "") +MAKE_WORD_CUSTOM(enable_mandatory, "") +MAKE_WORD_CUSTOM(service_mandatory, "") // more common names that don't need translations MAKE_NOTRANSLATION(1x3min, "1x3min") diff --git a/src/system.cpp b/src/system.cpp index c4c6ed2cb..66931ae40 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -261,12 +261,40 @@ void System::store_nvs_values() { } // restart EMS-ESP -void System::system_restart() { - LOG_INFO("Restarting EMS-ESP..."); +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 ESP.restart(); #endif } @@ -458,7 +486,8 @@ void System::button_OnDblClick(PButton & b) { // button long press void System::button_OnLongPress(PButton & b) { - LOG_NOTICE("Button pressed - long press"); + LOG_NOTICE("Button pressed - long press - restart other partition"); + EMSESP::system_.system_restart("boot"); } // button indefinite press @@ -1511,9 +1540,13 @@ bool System::load_board_profile(std::vector & data, const std::string & return true; } -// restart command - perform a hard reset by setting flag +// restart command - perform a hard reset bool System::command_restart(const char * value, const int8_t id) { - restart_requested(true); + if (value != nullptr && value[0] == '\0') { + EMSESP::system_.system_restart(value); + } else { + EMSESP::system_.system_restart(); + } return true; } diff --git a/src/system.h b/src/system.h index b7dea5c9a..4157bab81 100644 --- a/src/system.h +++ b/src/system.h @@ -69,7 +69,7 @@ class System { std::string reset_reason(uint8_t cpu) const; void store_nvs_values(); - void system_restart(); + void system_restart(const char * partition = nullptr); void format(uuid::console::Shell & shell); void upload_status(bool in_progress); bool upload_status(); diff --git a/src/version.h b/src/version.h index 245a6b5a4..f186bb10a 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define EMSESP_APP_VERSION "3.6.5-dev.17" +#define EMSESP_APP_VERSION "3.6.5-dev.18"