Skip to content

Commit

Permalink
Merge pull request #1661 from MichaelDvP/dev
Browse files Browse the repository at this point in the history
add telnet command to reboot to previous version #1657
  • Loading branch information
proddy authored Mar 16, 2024
2 parents 2efb9d1 + 9945b8d commit 2739712
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 17 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mqtt|ota|ntp|ap> <enable|disable>` [#1663](https://github.com/emsesp/EMS-ESP32/issues/1663)

## Fixed

Expand All @@ -45,4 +47,5 @@
- Length of mqtt Broker adress [#1619](https://github.com/emsesp/EMS-ESP32/issues/1619)
- C++ optimizations - see <https://github.com/emsesp/EMS-ESP32/pull/1615>
- 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
9 changes: 9 additions & 0 deletions esp32_partition_16M_factory.csv
Original file line number Diff line number Diff line change
@@ -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,
51 changes: 48 additions & 3 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,17 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
});
});

commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, string_vector{F_(restart)}, [](Shell & shell, const std::vector<std::string> & 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<std::string> & 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,
Expand Down Expand Up @@ -344,6 +352,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
//
Expand Down
7 changes: 5 additions & 2 deletions src/emsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1819,8 +1819,11 @@ bool EMSdevice::handle_telegram(std::shared_ptr<const Telegram> 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) {
Expand Down
13 changes: 11 additions & 2 deletions src/emsesp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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());

Expand Down
4 changes: 4 additions & 0 deletions src/locale_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -140,6 +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(partitionname_optional, "[partitionsname]")
MAKE_WORD_CUSTOM(data_optional, "[data]")
MAKE_WORD_CUSTOM(nvs_optional, "[nvs]")
MAKE_WORD_CUSTOM(offset_optional, "[offset]")
Expand All @@ -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, "<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")
Expand Down
45 changes: 39 additions & 6 deletions src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1511,9 +1540,13 @@ bool System::load_board_profile(std::vector<int8_t> & 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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.6.5-dev.17"
#define EMSESP_APP_VERSION "3.6.5-dev.18"

0 comments on commit 2739712

Please sign in to comment.