From 3a1b7cae67581414e4dd6e956c246daec6e60d81 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Fri, 29 Sep 2023 10:19:34 +0200 Subject: [PATCH 1/3] avoid possible div-zero --- src/web/WebStatusService.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/web/WebStatusService.cpp b/src/web/WebStatusService.cpp index b4ee7eaab..7ca471be9 100644 --- a/src/web/WebStatusService.cpp +++ b/src/web/WebStatusService.cpp @@ -148,7 +148,7 @@ void WebStatusService::webStatusService(AsyncWebServerRequest * request) { statJson["f"] = EMSESP::txservice_.telegram_write_fail_count(); statJson["q"] = EMSESP::txservice_.write_quality(); - if (EMSESP::temperaturesensor_.sensor_enabled()) { + if (EMSESP::sensor_enabled()) { statJson = statsJson.createNestedObject(); statJson["id"] = 3; statJson["s"] = EMSESP::temperaturesensor_.reads(); @@ -175,8 +175,9 @@ void WebStatusService::webStatusService(AsyncWebServerRequest * request) { statJson["id"] = 6; statJson["s"] = WebAPIService::api_count(); // + WebAPIService::api_fails(); statJson["f"] = WebAPIService::api_fails(); - statJson["q"] = - WebAPIService::api_count() == 0 ? 100 : 100 - (uint8_t)((100 * WebAPIService::api_fails()) / (WebAPIService::api_count() + WebAPIService::api_fails())); + statJson["q"] = (WebAPIService::api_count() + WebAPIService::api_fails()) == 0 + ? 100 + : 100 - (uint8_t)((100 * WebAPIService::api_fails()) / (WebAPIService::api_count() + WebAPIService::api_fails())); #ifndef EMSESP_STANDALONE if (EMSESP::system_.syslog_enabled()) { @@ -184,7 +185,7 @@ void WebStatusService::webStatusService(AsyncWebServerRequest * request) { statJson["id"] = 7; statJson["s"] = EMSESP::system_.syslog_count(); statJson["f"] = EMSESP::system_.syslog_fails(); - statJson["q"] = EMSESP::system_.syslog_count() == 0 + statJson["q"] = (EMSESP::system_.syslog_count() + EMSESP::system_.syslog_fails()) == 0 ? 100 : 100 - (uint8_t)((100 * EMSESP::system_.syslog_fails()) / (EMSESP::system_.syslog_count() + EMSESP::system_.syslog_fails())); } From 2e25e46f6f73c23915221561f8b0ba52b6462550 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Fri, 29 Sep 2023 10:20:17 +0200 Subject: [PATCH 2/3] temperaturesensor commands only if enabled (gpio != 0) --- src/command.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/command.cpp b/src/command.cpp index aaeaa9034..ce269c332 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -550,11 +550,11 @@ bool Command::device_has_commands(const uint8_t device_type) { } if (device_type == EMSdevice::DeviceType::TEMPERATURESENSOR) { - return true; + return EMSESP::sensor_enabled(); } if (device_type == EMSdevice::DeviceType::ANALOGSENSOR) { - return EMSESP::system_.analog_enabled(); + return EMSESP::analog_enabled(); } for (const auto & emsdevice : EMSESP::emsdevices) { @@ -576,8 +576,10 @@ void Command::show_devices(uuid::console::Shell & shell) { shell.printf("%s ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::SYSTEM)); shell.printf("%s ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::CUSTOM)); shell.printf("%s ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::SCHEDULER)); - shell.printf("%s ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::TEMPERATURESENSOR)); - if (EMSESP::analogsensor_.analog_enabled()) { + if (EMSESP::sensor_enabled()) { + shell.printf("%s ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::TEMPERATURESENSOR)); + } + if (EMSESP::analog_enabled()) { shell.printf("%s ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::ANALOGSENSOR)); } @@ -627,13 +629,15 @@ void Command::show_all(uuid::console::Shell & shell) { show(shell, EMSdevice::DeviceType::SCHEDULER, true); // show sensors - shell.print(COLOR_BOLD_ON); - shell.print(COLOR_YELLOW); - shell.printf(" %s: ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::TEMPERATURESENSOR)); - shell.print(COLOR_RESET); - show(shell, EMSdevice::DeviceType::TEMPERATURESENSOR, true); + if (EMSESP::sensor_enabled()) { + shell.print(COLOR_BOLD_ON); + shell.print(COLOR_YELLOW); + shell.printf(" %s: ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::TEMPERATURESENSOR)); + shell.print(COLOR_RESET); + show(shell, EMSdevice::DeviceType::TEMPERATURESENSOR, true); + } - if (EMSESP::analogsensor_.analog_enabled()) { + if (EMSESP::analog_enabled()) { shell.print(COLOR_BOLD_ON); shell.print(COLOR_YELLOW); shell.printf(" %s: ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::ANALOGSENSOR)); From 99467558b4533b552ec01c6c58f3c3098f65fefe Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Fri, 29 Sep 2023 10:21:20 +0200 Subject: [PATCH 3/3] check each single nvs values before writing it --- src/devices/boiler.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/devices/boiler.cpp b/src/devices/boiler.cpp index 3dba58e67..6454c919f 100644 --- a/src/devices/boiler.cpp +++ b/src/devices/boiler.cpp @@ -895,13 +895,16 @@ Boiler::Boiler(uint8_t device_type, int8_t device_id, uint8_t product_id, const void Boiler::store_energy() { // only write if something is changed - if (nrgHeatF_ != EMSESP::nvs_.getDouble(FL_(nrgHeat)[0]) || nrgWwF_ != EMSESP::nvs_.getDouble(FL_(nrgWw)[0]) - || nomPower_ != EMSESP::nvs_.getUChar(FL_(nomPower)[0])) { + if (nrgHeatF_ != EMSESP::nvs_.getDouble(FL_(nrgHeat)[0])) { EMSESP::nvs_.putDouble(FL_(nrgHeat)[0], nrgHeatF_); - EMSESP::nvs_.putDouble(FL_(nrgWw)[0], nrgWwF_); - EMSESP::nvs_.putUChar(FL_(nomPower)[0], nomPower_); - LOG_DEBUG("energy values stored"); } + if (nrgWwF_ != EMSESP::nvs_.getDouble(FL_(nrgWw)[0])) { + EMSESP::nvs_.putDouble(FL_(nrgWw)[0], nrgWwF_); + } + if (nomPower_ != EMSESP::nvs_.getUChar(FL_(nomPower)[0])) { + EMSESP::nvs_.putUChar(FL_(nomPower)[0], nomPower_); + } + // LOG_DEBUG("energy values stored"); } // Check if hot tap water or heating is active