Merge pull request #2878 from MichaelDvP/dev

fix selflowtemp #2876 and other
This commit is contained in:
Proddy
2026-01-01 17:04:00 +01:00
committed by GitHub
6 changed files with 54 additions and 85 deletions

View File

@@ -6,6 +6,12 @@ For more details go to [emsesp.org](https://emsesp.org/).
## Added ## Added
- update time safed in nvs
## Fixed ## Fixed
- selflowtemp [#2876](https://github.com/emsesp/EMS-ESP32/issues/2876)
## Changed ## Changed
- snapshot gpios in temporarly ram

View File

@@ -107,8 +107,6 @@ bool System::led_flash_timer_ = false;
// GPIOs // GPIOs
std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::valid_system_gpios_; std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::valid_system_gpios_;
std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::used_gpios_; std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::used_gpios_;
std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::snapshot_used_gpios_;
std::vector<uint8_t, AllocatorPSRAM<uint8_t>> System::snapshot_valid_system_gpios_;
// find the index of the language // find the index of the language
// 0 = EN, 1 = DE, etc... // 0 = EN, 1 = DE, etc...
@@ -319,12 +317,16 @@ void System::get_partition_info() {
auto current_partition = (const char *)esp_ota_get_running_partition()->label; auto current_partition = (const char *)esp_ota_get_running_partition()->label;
// update the current version and partition name in NVS if not already set (saves on flash wearing) // update the current version and partition name in NVS if not already set (saves on flash wearing)
if (EMSESP::nvs_.isKey(current_partition)) { if (EMSESP::nvs_.getString(current_partition) != EMSESP_APP_VERSION || emsesp::EMSESP::nvs_.getBool(emsesp::EMSESP_NVS_BOOT_NEW_FIRMWARE, false)) {
if (EMSESP::nvs_.getString(current_partition) != EMSESP_APP_VERSION) { if (EMSESP::nvs_.getBool(emsesp::EMSESP_NVS_BOOT_NEW_FIRMWARE, false)) {
EMSESP::nvs_.putString(current_partition, EMSESP_APP_VERSION); EMSESP::nvs_.putBool(emsesp::EMSESP_NVS_BOOT_NEW_FIRMWARE, false);
} }
} else { EMSESP::nvs_.putString(current_partition, EMSESP_APP_VERSION);
EMSESP::nvs_.putString(current_partition, EMSESP_APP_VERSION); // create new entry char c[20];
snprintf(c, sizeof(c), "d_%s", current_partition);
auto t = time(nullptr);
// write timestamp always with new version, if clock is not set, this will be updated with ntp
EMSESP::nvs_.putULong(c, t);
} }
// Loop through all available partitions and update map with the version info pulled from NVS // Loop through all available partitions and update map with the version info pulled from NVS
@@ -347,16 +349,17 @@ void System::get_partition_info() {
// get the version from the NVS store, and add to map // get the version from the NVS store, and add to map
if (is_valid) { if (is_valid) {
PartitionInfo p_info; PartitionInfo p_info;
p_info.version = ""; // if there is an entry for this partition in NVS, get it's version from NVS
p_info.install_date = ""; // this will be added later when NTP is connected p_info.version = EMSESP::nvs_.getString(part->label, "").c_str();
char c[20];
snprintf(c, sizeof(c), "d_%s", (const char *)part->label);
time_t d = EMSESP::nvs_.getULong(c, 0);
char time_string[25];
strftime(time_string, sizeof(time_string), "%FT%T", localtime(&d));
p_info.install_date = d > 1500000000L ? time_string : "";
p_info.size = part->size / 1024; // set size in KB p_info.size = part->size / 1024; // set size in KB
// if there is an entry for this partition in NVS, get it's version from NVS
if (EMSESP::nvs_.isKey(part->label)) {
p_info.version = EMSESP::nvs_.getString(part->label).c_str();
}
partition_info_[part->label] = p_info; partition_info_[part->label] = p_info;
} }
@@ -368,36 +371,21 @@ void System::get_partition_info() {
// set NTP install time/date for the current partition // set NTP install time/date for the current partition
// assumes NTP is connected and working // assumes NTP is connected and working
void System::set_partition_install_date(bool override) { void System::set_partition_install_date() {
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
auto current_partition = (const char *)esp_ota_get_running_partition()->label; auto current_partition = (const char *)esp_ota_get_running_partition()->label;
if (current_partition == nullptr) { if (current_partition == nullptr) {
return; // fail-safe return; // fail-safe
} }
// skip if it already has an install date, unless override is true char c[20];
if (!partition_info_[current_partition].install_date.empty() && !override) { snprintf(c, sizeof(c), "d_%s", current_partition);
return; time_t d = EMSESP::nvs_.getULong(c, 0);
if (d < 1500000000L) {
LOG_INFO("Firmware is fresh, setting the new install date in partition %s", current_partition);
auto t = time(nullptr) - uuid::get_uptime_sec();
EMSESP::nvs_.putULong(c, t);
} }
// EMSESP_NVS_BOOT_NEW_FIRMWARE is set in UploadFileService::uploadComplete()
auto is_fresh_firmware = EMSESP::nvs_.getBool(EMSESP_NVS_BOOT_NEW_FIRMWARE);
// always reset flag after setting the install date
EMSESP::nvs_.putBool(EMSESP_NVS_BOOT_NEW_FIRMWARE, false);
// check if the firmware is a new upload
if (is_fresh_firmware) {
LOG_DEBUG("Firmware is fresh, setting the new install date in partition %s", current_partition);
} else {
return; // skip, not new
}
// set current date/time from NTP
char time_string[25];
time_t now = time(nullptr);
strftime(time_string, sizeof(time_string), "%FT%T", localtime(&now));
partition_info_[current_partition].install_date = time_string;
LOG_DEBUG("Adding NTP install date %s to partition %s", time_string, current_partition);
#endif #endif
} }
@@ -1749,9 +1737,10 @@ void System::get_value_json(JsonObject output, const std::string & circuit, cons
if (circuit.length()) { if (circuit.length()) {
output["circuit"] = circuit; output["circuit"] = circuit;
} }
output["readable"] = true; output["readable"] = true;
output["writeable"] = (name == "showerTimer" || name == "showerAlert" || name == "enabled" || name == "hideLed" || name == "analogEnabled"); output["writeable"] =
output["visible"] = true; (name == "txpause" || name == "showerTimer" || name == "showerAlert" || name == "enabled" || name == "hideLed" || name == "analogEnabled");
output["visible"] = true;
if (val.is<bool>()) { if (val.is<bool>()) {
output["value"] = val.as<bool>(); output["value"] = val.as<bool>();
output["type"] = "boolean"; output["type"] = "boolean";
@@ -2541,11 +2530,7 @@ void System::ntp_connected(bool b) {
if (b != ntp_connected_) { if (b != ntp_connected_) {
if (b) { if (b) {
LOG_INFO("NTP connected"); LOG_INFO("NTP connected");
#ifdef EMSESP_DEBUG // reset the install date on startup if in debug mode set_partition_install_date();
set_partition_install_date(true);
#else
set_partition_install_date(false);
#endif
} else { } else {
LOG_WARNING("NTP disconnected"); // if turned off report it LOG_WARNING("NTP disconnected"); // if turned off report it
} }
@@ -2923,37 +2908,26 @@ std::vector<uint8_t> System::available_gpios() {
} }
// make a snapshot of the current GPIOs // make a snapshot of the current GPIOs
void System::make_snapshot_gpios() { void System::make_snapshot_gpios(std::vector<int8_t> & u_gpios, std::vector<int8_t> & s_gpios) {
snapshot_used_gpios_.clear();
for (const auto & gpio : used_gpios_) { for (const auto & gpio : used_gpios_) {
snapshot_used_gpios_.push_back(gpio); u_gpios.push_back(gpio);
} }
snapshot_valid_system_gpios_.clear();
for (const auto & gpio : valid_system_gpios_) { for (const auto & gpio : valid_system_gpios_) {
snapshot_valid_system_gpios_.push_back(gpio); s_gpios.push_back(gpio);
} }
} }
// restore the GPIOs from the snapshot // restore the GPIOs from the snapshot
void System::restore_snapshot_gpios() { void System::restore_snapshot_gpios(std::vector<int8_t> & u_gpios, std::vector<int8_t> & s_gpios) {
used_gpios_.clear(); used_gpios_.clear();
for (const auto & gpio : snapshot_used_gpios_) { for (const auto & gpio : u_gpios) {
used_gpios_.push_back(gpio); used_gpios_.push_back(gpio);
} }
valid_system_gpios_.clear(); valid_system_gpios_.clear();
for (const auto & gpio : snapshot_valid_system_gpios_) { for (const auto & gpio : s_gpios) {
valid_system_gpios_.push_back(gpio); valid_system_gpios_.push_back(gpio);
} }
// clear the snapshot
clear_snapshot_gpios();
}
void System::clear_snapshot_gpios() {
snapshot_used_gpios_.clear();
snapshot_valid_system_gpios_.clear();
} }
} // namespace emsesp } // namespace emsesp

View File

@@ -163,9 +163,8 @@ class System {
static bool add_gpio(uint8_t pin, const char * source_name); static bool add_gpio(uint8_t pin, const char * source_name);
static std::vector<uint8_t> available_gpios(); static std::vector<uint8_t> available_gpios();
static bool load_board_profile(std::vector<int8_t> & data, const std::string & board_profile); static bool load_board_profile(std::vector<int8_t> & data, const std::string & board_profile);
static void make_snapshot_gpios(); static void make_snapshot_gpios(std::vector<int8_t> & u_gpios, std::vector<int8_t> & s_gpios);
static void restore_snapshot_gpios(); static void restore_snapshot_gpios(std::vector<int8_t> & u_gpios, std::vector<int8_t> & s_gpios);
static void clear_snapshot_gpios();
static bool readCommand(const char * data); static bool readCommand(const char * data);
@@ -392,7 +391,7 @@ class System {
uint8_t systemStatus_; // uses SYSTEM_STATUS enum uint8_t systemStatus_; // uses SYSTEM_STATUS enum
void set_partition_install_date(bool override = false); void set_partition_install_date();
// button // button
static PButton myPButton_; // PButton instance static PButton myPButton_; // PButton instance
@@ -438,10 +437,8 @@ class System {
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> string_range_to_vector(const std::string & range); static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> string_range_to_vector(const std::string & range);
// GPIOs // GPIOs
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> valid_system_gpios_; // list of valid GPIOs for the ESP32 board that can be used static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> valid_system_gpios_; // list of valid GPIOs for the ESP32 board that can be used
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> used_gpios_; // list of GPIOs used by the application static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> used_gpios_; // list of GPIOs used by the application
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> snapshot_used_gpios_; // snapshot of the used GPIOs
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> snapshot_valid_system_gpios_; // snapshot of the valid GPIOs
int8_t wifi_quality(int8_t dBm); int8_t wifi_quality(int8_t dBm);

View File

@@ -2478,9 +2478,9 @@ bool Boiler::set_flow_temp(const char * value, const int8_t id) {
uint8_t v1 = v; uint8_t v1 = v;
if (has_telegram_id(0xE4)) { if (has_telegram_id(0xE4)) {
EMSESP::txservice_.add(Telegram::Operation::TX_WRITE, device_id(), EMS_TYPE_UBASetPoints2, 1, &v1, 1, 0, false); EMSESP::txservice_.add(Telegram::Operation::TX_WRITE, device_id(), EMS_TYPE_UBASetPoints2, 1, &v1, 1, 0, false);
} else {
EMSESP::txservice_.add(Telegram::Operation::TX_WRITE, device_id(), EMS_TYPE_UBASetPoints, 0, &v1, 1, 0, false);
} }
// always write to 0x1A
EMSESP::txservice_.add(Telegram::Operation::TX_WRITE, device_id(), EMS_TYPE_UBASetPoints, 0, &v1, 1, 0, false);
return true; return true;
} }

View File

@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.8.1-dev.1" #define EMSESP_APP_VERSION "3.8.1-dev.2"

View File

@@ -92,7 +92,9 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) {
const WebSettings original_settings(settings); const WebSettings original_settings(settings);
// make a snapshot of the current GPIOs // make a snapshot of the current GPIOs
EMSESP::system_.make_snapshot_gpios(); std::vector<int8_t> used_gpios;
std::vector<int8_t> system_gpios;
EMSESP::system_.make_snapshot_gpios(used_gpios, system_gpios);
reset_flags(); reset_flags();
@@ -111,13 +113,6 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) {
settings.eth_clock_mode = root["eth_clock_mode"]; settings.eth_clock_mode = root["eth_clock_mode"];
settings.led_type = root["led_type"]; // 1 = RGB-LED settings.led_type = root["led_type"]; // 1 = RGB-LED
#if defined(EMSESP_DEBUG)
EMSESP::logger().debug("NVS boot value=[%s], current board_profile=[%s], new board_profile=[%s]",
EMSESP::nvs_.getString("boot").c_str(),
original_settings.board_profile.c_str(),
settings.board_profile.c_str());
#endif
// see if the user has changed the board profile // see if the user has changed the board profile
// this will set: led_gpio, dallas_gpio, rx_gpio, tx_gpio, pbutton_gpio, phy_type, eth_power, eth_phy_addr, eth_clock_mode, led_type // this will set: led_gpio, dallas_gpio, rx_gpio, tx_gpio, pbutton_gpio, phy_type, eth_power, eth_phy_addr, eth_clock_mode, led_type
// this will always run when EMS-ESP starts since original_settings{} is empty // this will always run when EMS-ESP starts since original_settings{} is empty
@@ -315,16 +310,13 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) {
// replace settings with original settings // replace settings with original settings
settings = original_settings; // the original settings are still valid settings = original_settings; // the original settings are still valid
// restore the GPIOs from the snapshot // restore the GPIOs from the snapshot
EMSESP::system_.restore_snapshot_gpios(); EMSESP::system_.restore_snapshot_gpios(used_gpios, system_gpios);
// report the error to WebUI // report the error to WebUI
EMSESP::system_.systemStatus(SYSTEM_STATUS::SYSTEM_STATUS_INVALID_GPIO); EMSESP::system_.systemStatus(SYSTEM_STATUS::SYSTEM_STATUS_INVALID_GPIO);
return StateUpdateResult::ERROR; // don't save the settings if the GPIOs are invalid return StateUpdateResult::ERROR; // don't save the settings if the GPIOs are invalid
} }
// clean up snapshot of the GPIOs
EMSESP::system_.clear_snapshot_gpios();
// save the setting internally, for reference later // save the setting internally, for reference later
EMSESP::system_.store_settings(settings); EMSESP::system_.store_settings(settings);