From 8dfc84eac26476930828a8a4e33b25f8a989494e Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Wed, 13 Mar 2024 16:03:28 +0100 Subject: [PATCH 1/7] add `restart other` command to change partition #1657 --- CHANGELOG_LATEST.md | 3 ++- src/console.cpp | 14 +++++++++++--- src/locale_common.h | 1 + src/system.cpp | 34 +++++++++++++++++++++++++++++----- src/system.h | 2 +- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index dfc3819ab..cb5e05e25 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -20,8 +20,9 @@ - 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 other` and button long press to start with other partition [#1657](https://github.com/emsesp/EMS-ESP32/issues/1657) ## Fixed diff --git a/src/console.cpp b/src/console.cpp index a8a88f4d3..ef4187017 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_(other_optional)}, + [](Shell & shell, const std::vector & arguments) { + if (arguments.size()) { + to_app(shell).system_.system_restart(arguments.front() == "other"); + } else { + to_app(shell).system_.system_restart(); + } + }); commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, diff --git a/src/locale_common.h b/src/locale_common.h index 59e965ad8..f6ae44e8d 100644 --- a/src/locale_common.h +++ b/src/locale_common.h @@ -140,6 +140,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(other_optional, "[other]") MAKE_WORD_CUSTOM(data_optional, "[data]") MAKE_WORD_CUSTOM(nvs_optional, "[nvs]") MAKE_WORD_CUSTOM(offset_optional, "[offset]") diff --git a/src/system.cpp b/src/system.cpp index c4c6ed2cb..e984cf67e 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -261,12 +261,31 @@ void System::store_nvs_values() { } // restart EMS-ESP -void System::system_restart() { - LOG_INFO("Restarting EMS-ESP..."); +void System::system_restart(const bool other_partition) { + if (other_partition) { + LOG_INFO("Restarting EMS-ESP to other partition..."); + } 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 } @@ -458,7 +477,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 - boot to other partition"); + EMSESP::system_.system_restart(true); } // button indefinite press @@ -1511,9 +1531,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[0] == '1' || strcmp(value, "true") == 0 || strcmp(value, "other") == 0) { + EMSESP::system_.system_restart(true); + } else { + EMSESP::system_.system_restart(false); + } return true; } diff --git a/src/system.h b/src/system.h index b7dea5c9a..965de2d05 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 bool other_partition = false); void format(uuid::console::Shell & shell); void upload_status(bool in_progress); bool upload_status(); From a5708e11ba5da9503db4b0bac6c4acbec6fc5eb9 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Wed, 13 Mar 2024 16:21:41 +0100 Subject: [PATCH 2/7] update packages --- interface/package.json | 8 ++-- interface/yarn.lock | 96 +++++++++++++++++++++--------------------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/interface/package.json b/interface/package.json index 4966e110c..c8cc921ca 100644 --- a/interface/package.json +++ b/interface/package.json @@ -26,14 +26,14 @@ "@babel/core": "^7.24.0", "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.0", - "@mui/icons-material": "^5.15.12", - "@mui/material": "^5.15.12", + "@mui/icons-material": "^5.15.13", + "@mui/material": "^5.15.13", "@table-library/react-table-library": "4.1.7", "@types/imagemin": "^8.0.5", "@types/lodash-es": "^4.17.12", - "@types/node": "^20.11.26", + "@types/node": "^20.11.27", "@types/react": "^18.2.65", - "@types/react-dom": "^18.2.21", + "@types/react-dom": "^18.2.22", "@types/react-router-dom": "^5.3.3", "alova": "^2.17.1", "async-validator": "^4.2.5", diff --git a/interface/yarn.lock b/interface/yarn.lock index 7fcb305e5..8104db8fd 100644 --- a/interface/yarn.lock +++ b/interface/yarn.lock @@ -992,14 +992,14 @@ __metadata: languageName: node linkType: hard -"@mui/base@npm:5.0.0-beta.38": - version: 5.0.0-beta.38 - resolution: "@mui/base@npm:5.0.0-beta.38" +"@mui/base@npm:5.0.0-beta.39": + version: 5.0.0-beta.39 + resolution: "@mui/base@npm:5.0.0-beta.39" dependencies: "@babel/runtime": "npm:^7.23.9" "@floating-ui/react-dom": "npm:^2.0.8" "@mui/types": "npm:^7.2.13" - "@mui/utils": "npm:^5.15.12" + "@mui/utils": "npm:^5.15.13" "@popperjs/core": "npm:^2.11.8" clsx: "npm:^2.1.0" prop-types: "npm:^15.8.1" @@ -1010,20 +1010,20 @@ __metadata: peerDependenciesMeta: "@types/react": optional: true - checksum: 10/551eacaf4de2f0c049694ee5c1fbc2a05d60c580984caf9b2a8c1e92dbaf4041b4e138904f8411c8ec65c2436dba91b6a7f3cfdd188075f1423a90963cab2cab + checksum: 10/320aeedb6c32df9807e2581065e98c3dd0510dcd8666c1c4804fc2281fa42e4e2111152961ded0ba1c3b9dc320936ee73d1a0861c0985a0da86a7bd7bf8cbada languageName: node linkType: hard -"@mui/core-downloads-tracker@npm:^5.15.12": - version: 5.15.12 - resolution: "@mui/core-downloads-tracker@npm:5.15.12" - checksum: 10/bbece78282ca224ee8aee67f67c7840962ccdfa9753e93c0c4ede2d6a37853ad7523996c39be530077a7ecb49fb82f6e60bed7ce7937b05ca485a2d091aac3d8 +"@mui/core-downloads-tracker@npm:^5.15.13": + version: 5.15.13 + resolution: "@mui/core-downloads-tracker@npm:5.15.13" + checksum: 10/988e5c7ff9c185c603b6c5d533e6dbb305b5d334c3f2b4ebcc9e2a5fb7dea141ccb05f70aa4cbf972e2556a67a0d928c7bd3bf7ab5d41b139fd0532af64e2c65 languageName: node linkType: hard -"@mui/icons-material@npm:^5.15.12": - version: 5.15.12 - resolution: "@mui/icons-material@npm:5.15.12" +"@mui/icons-material@npm:^5.15.13": + version: 5.15.13 + resolution: "@mui/icons-material@npm:5.15.13" dependencies: "@babel/runtime": "npm:^7.23.9" peerDependencies: @@ -1033,20 +1033,20 @@ __metadata: peerDependenciesMeta: "@types/react": optional: true - checksum: 10/06e168c45b39d699745a823a8563795b44b7bdfb779bada97f67799b94ff34acd853031dc359b9984115c1b6fd7b56429cc121187aef95e2e27ef0a8c2a2208d + checksum: 10/89e79ebe4a0ab8594934f4056034dcffe57cc7c4468717545d67310cb74626c38ea79a7129d16fbf265745ceca7e8c35d21c3f59a4519e0776f774f6ea228fd3 languageName: node linkType: hard -"@mui/material@npm:^5.15.12": - version: 5.15.12 - resolution: "@mui/material@npm:5.15.12" +"@mui/material@npm:^5.15.13": + version: 5.15.13 + resolution: "@mui/material@npm:5.15.13" dependencies: "@babel/runtime": "npm:^7.23.9" - "@mui/base": "npm:5.0.0-beta.38" - "@mui/core-downloads-tracker": "npm:^5.15.12" - "@mui/system": "npm:^5.15.12" + "@mui/base": "npm:5.0.0-beta.39" + "@mui/core-downloads-tracker": "npm:^5.15.13" + "@mui/system": "npm:^5.15.13" "@mui/types": "npm:^7.2.13" - "@mui/utils": "npm:^5.15.12" + "@mui/utils": "npm:^5.15.13" "@types/react-transition-group": "npm:^4.4.10" clsx: "npm:^2.1.0" csstype: "npm:^3.1.3" @@ -1066,16 +1066,16 @@ __metadata: optional: true "@types/react": optional: true - checksum: 10/adee362d8367c4dec08fd4cec6b41fbe05699290b98e334c0203a73a4a13c24f2f4387b7f54b2000704b33182c3704fe873222227ccb58cc2099f9124bf02763 + checksum: 10/565e219d58f93bd8cdcc5e9d432046d6bfc3b2d81e3f1b8d4b93347f895f26d3f348a312fe2b943c41275fb3ea492e76d9651ce16f64e5773fe2be07309c67a2 languageName: node linkType: hard -"@mui/private-theming@npm:^5.15.12": - version: 5.15.12 - resolution: "@mui/private-theming@npm:5.15.12" +"@mui/private-theming@npm:^5.15.13": + version: 5.15.13 + resolution: "@mui/private-theming@npm:5.15.13" dependencies: "@babel/runtime": "npm:^7.23.9" - "@mui/utils": "npm:^5.15.12" + "@mui/utils": "npm:^5.15.13" prop-types: "npm:^15.8.1" peerDependencies: "@types/react": ^17.0.0 || ^18.0.0 @@ -1083,7 +1083,7 @@ __metadata: peerDependenciesMeta: "@types/react": optional: true - checksum: 10/9e4e144d3de79536ec7cb46c98cabbe334ec7368c49ec3aa5a312e37fb8571cc95bad60b799e3252bbce7f2de6cc467f250cb217ca60316ead5303b5f5f2a660 + checksum: 10/677fa31f8caa1f3ae4b44806b2cf340b23eb9132baaca1421f615d1ef1aae5560a7c452b4f79e38bdb865a54306ba65c4ac95c1f4c0216f89217dd19fb320747 languageName: node linkType: hard @@ -1108,15 +1108,15 @@ __metadata: languageName: node linkType: hard -"@mui/system@npm:^5.15.12": - version: 5.15.12 - resolution: "@mui/system@npm:5.15.12" +"@mui/system@npm:^5.15.13": + version: 5.15.13 + resolution: "@mui/system@npm:5.15.13" dependencies: "@babel/runtime": "npm:^7.23.9" - "@mui/private-theming": "npm:^5.15.12" + "@mui/private-theming": "npm:^5.15.13" "@mui/styled-engine": "npm:^5.15.11" "@mui/types": "npm:^7.2.13" - "@mui/utils": "npm:^5.15.12" + "@mui/utils": "npm:^5.15.13" clsx: "npm:^2.1.0" csstype: "npm:^3.1.3" prop-types: "npm:^15.8.1" @@ -1132,7 +1132,7 @@ __metadata: optional: true "@types/react": optional: true - checksum: 10/23642eea1f5948cf0c57674569af9df3e7630d888da80d5d34afe6259a21631424f86b23a431a76a4046a6caa738d81d8a1b36ca438c6695aa93ca62b08afd50 + checksum: 10/678a741d872a4badba32f7b88d7db969af96cf3e029f984abd0f58e88e95203a1ee3f4110f970a015d15f7e9171d0dea57040cdb8419901236790df4900de017 languageName: node linkType: hard @@ -1148,9 +1148,9 @@ __metadata: languageName: node linkType: hard -"@mui/utils@npm:^5.15.12": - version: 5.15.12 - resolution: "@mui/utils@npm:5.15.12" +"@mui/utils@npm:^5.15.13": + version: 5.15.13 + resolution: "@mui/utils@npm:5.15.13" dependencies: "@babel/runtime": "npm:^7.23.9" "@types/prop-types": "npm:^15.7.11" @@ -1162,7 +1162,7 @@ __metadata: peerDependenciesMeta: "@types/react": optional: true - checksum: 10/e4c40d73a0367ccc89491835fb98baafaea046fbcdd46d407689b8cda95ead1d45bb3b4364a135c1fa20d1c3b23ad69705e228943e5995d597860be9b5ab8c2b + checksum: 10/16f78b87bb88f6e1131ac1ff426d4fda128d56bbbca53b98ae45ce45bf0bb826dba66cbff98b25d842225fd1a983c17ae83b43ead17c9add88789eb9514d065b languageName: node linkType: hard @@ -1590,12 +1590,12 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:^20.11.26": - version: 20.11.26 - resolution: "@types/node@npm:20.11.26" +"@types/node@npm:^20.11.27": + version: 20.11.27 + resolution: "@types/node@npm:20.11.27" dependencies: undici-types: "npm:~5.26.4" - checksum: 10/37a69017fc0e70bd52e106a7a0de21f78b29a869b2ab7b0539438ee6ce91cb9b49b80d6b68108e88fcc20e24cdc4dc00f6e8e1c28215d93412cb19a303572130 + checksum: 10/4be53485d499dd7c7896190e76a0ce1f6c6917d1f4d0b4b240b3670160fcbc548daed32beaac0fc92429b37dbeaa2496fc56f460acaab969bddb77394318a89b languageName: node linkType: hard @@ -1620,12 +1620,12 @@ __metadata: languageName: node linkType: hard -"@types/react-dom@npm:^18.2.21": - version: 18.2.21 - resolution: "@types/react-dom@npm:18.2.21" +"@types/react-dom@npm:^18.2.22": + version: 18.2.22 + resolution: "@types/react-dom@npm:18.2.22" dependencies: "@types/react": "npm:*" - checksum: 10/5c714bc69c3cf979dbf3fb8c66fc42b5b740af54d98c1037c593ac9ad54e5107cfc39fcba8c550f8df924670f55b411898d53c6166a2b15b4ed44a248a358590 + checksum: 10/310da22244c1bb65a7f213f8727bda821dd211cfb2dd62d1f9b28dd50ef1c196d59e908494bd5f25c13a3844343f3a6135f39fb830aca6f79646fa56c1b56c08 languageName: node linkType: hard @@ -1851,16 +1851,16 @@ __metadata: "@babel/core": "npm:^7.24.0" "@emotion/react": "npm:^11.11.4" "@emotion/styled": "npm:^11.11.0" - "@mui/icons-material": "npm:^5.15.12" - "@mui/material": "npm:^5.15.12" + "@mui/icons-material": "npm:^5.15.13" + "@mui/material": "npm:^5.15.13" "@preact/compat": "npm:^17.1.2" "@preact/preset-vite": "npm:^2.8.1" "@table-library/react-table-library": "npm:4.1.7" "@types/imagemin": "npm:^8.0.5" "@types/lodash-es": "npm:^4.17.12" - "@types/node": "npm:^20.11.26" + "@types/node": "npm:^20.11.27" "@types/react": "npm:^18.2.65" - "@types/react-dom": "npm:^18.2.21" + "@types/react-dom": "npm:^18.2.22" "@types/react-router-dom": "npm:^5.3.3" "@typescript-eslint/eslint-plugin": "npm:^7.2.0" "@typescript-eslint/parser": "npm:^7.2.0" From ce8d8699c34404f358bb970961db8dae26d6582e Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Fri, 15 Mar 2024 13:57:03 +0100 Subject: [PATCH 3/7] add 16M partitions with factory and two ota --- esp32_partition_16M_factory.csv | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 esp32_partition_16M_factory.csv 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 From 8a0152ebe61e882fea81afd824dd016c9fc583d4 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Fri, 15 Mar 2024 13:57:52 +0100 Subject: [PATCH 4/7] log running partition on startup --- src/emsesp.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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()); From 77ad209ce1553ce7403c8eb47e6fa1e99b924043 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Fri, 15 Mar 2024 13:59:20 +0100 Subject: [PATCH 5/7] stop fetching empty messages after 5 min --- src/emsdevice.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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) { From eec3b3be7a691c60a5a4c6ce79d98c55b6810a25 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Fri, 15 Mar 2024 14:42:47 +0100 Subject: [PATCH 6/7] restart option partitionname, console-command `set service` --- src/console.cpp | 41 ++++++++++++++++++++++++++++++-- src/locale_common.h | 5 +++- src/system.cpp | 57 ++++++++++++++++++++++++++------------------- src/system.h | 2 +- 4 files changed, 77 insertions(+), 28 deletions(-) diff --git a/src/console.cpp b/src/console.cpp index ef4187017..6ec881398 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -201,10 +201,10 @@ static void setup_commands(std::shared_ptr & 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 & 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) { 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/locale_common.h b/src/locale_common.h index f6ae44e8d..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,7 +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(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, "") +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 e984cf67e..66931ae40 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -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 & 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; } diff --git a/src/system.h b/src/system.h index 965de2d05..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(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(); From 9945b8d09fa75dae2dca2b56aeb9d8f03862e78d Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Fri, 15 Mar 2024 14:50:01 +0100 Subject: [PATCH 7/7] changelog, 3.6.5-dev.18 --- CHANGELOG_LATEST.md | 6 ++++-- src/version.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index cb5e05e25..dab01489b 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -22,7 +22,8 @@ - custom variables [#1423](https://github.com/emsesp/EMS-ESP32/issues/1423) - 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 other` and button long press to start with other partition [#1657](https://github.com/emsesp/EMS-ESP32/issues/1657) +- 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 @@ -46,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/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"