From b2e554c87f12971b44544563d032df68631e6b6c Mon Sep 17 00:00:00 2001 From: harrymayr <104222469+harrymayr@users.noreply.github.com> Date: Sun, 18 Dec 2022 23:50:26 +0100 Subject: [PATCH] Fixed WDT resets for mqtt discovery - Fixed Watchdog resets on registering HA discovery topics. Need to put all messages into publish queue. For that several loops needed for the boiler, - increade MQTT queue to 25 - added gas meter reading in boiler list - back to custom MMU settings --- platformio.ini | 10 +- src/devices/boiler.cpp | 491 +++++++++++++++++++------------------ src/devices/boiler.h | 4 +- src/devices/thermostat.cpp | 4 +- src/emsesp.cpp | 4 +- src/emsesp.h | 3 +- src/locale_EN.h | 1 + src/mqtt.cpp | 16 +- src/mqtt.h | 2 +- src/system.cpp | 21 +- src/system.h | 4 +- src/test/test.cpp | 1 + src/version.h | 2 +- 13 files changed, 295 insertions(+), 268 deletions(-) diff --git a/platformio.ini b/platformio.ini index da0cc711..59794024 100644 --- a/platformio.ini +++ b/platformio.ini @@ -70,10 +70,10 @@ board_build.f_cpu = 160000000L ; 160MHz ; eagle.flash.4m2m.ld = 1019 KB sketch, 2024 KB SPIFFS. 4KB EEPROM, 4KB RFCAL, 12KB WIFI stack, 1028 KB OTA & buffer ; board_build.ldscript = eagle.flash.4m2m.ld build_flags = ${common.build_flags} ${common.debug_flags} -; -D PIO_FRAMEWORK_ARDUINO_MMU_CUSTOM -; -D MMU_IRAM_SIZE=0xC000 -; -D MMU_ICACHE_SIZE=0x4000 -; -D MMU_IRAM_HEAP - -D FLASH_MAP_SUPPORT=1 + ;-D PIO_FRAMEWORK_ARDUINO_MMU_CUSTOM + ;-D MMU_IRAM_SIZE=0xC000 + ;-D MMU_ICACHE_SIZE=0x4000 + ;-D MMU_IRAM_HEAP + -D FLASH_MAP_SUPPORT=1 lib_ignore = AsyncTCP diff --git a/src/devices/boiler.cpp b/src/devices/boiler.cpp index 32551154..1aefa0ae 100644 --- a/src/devices/boiler.cpp +++ b/src/devices/boiler.cpp @@ -17,6 +17,7 @@ */ #include "boiler.h" +#include "system.h" namespace emsesp { @@ -145,187 +146,195 @@ void Boiler::register_mqtt_ha_config() { if (!Mqtt::connected()) { return; } - - // Create the Master device - DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_HA_CONFIG); - //StaticJsonDocument doc; - doc["name"] = FJSON("Service Code"); - doc["uniq_id"] = FJSON("boiler"); - doc["ic"] = FJSON("mdi:home-thermometer-outline"); - - char temp[128]; - snprintf_P(temp, sizeof(temp), PSTR("%s/boiler_data"), Mqtt::base().c_str()); - doc["stat_t"] = temp; - - doc["val_tpl"] = FJSON("{{value_json.serviceCode}}"); - JsonObject dev = doc.createNestedObject("dev"); - snprintf_P(temp, sizeof(temp), PSTR("%s Boiler"), Mqtt::base().c_str()); - dev["name"] = temp; - dev["sw"] = EMSESP_APP_VERSION; - dev["mf"] = brand_to_string(); - dev["mdl"] = name(); - JsonArray ids = dev.createNestedArray("ids"); - snprintf_P(temp, sizeof(temp), PSTR("%s-boiler"), Mqtt::base().c_str()); - ids.add(temp); - snprintf_P(temp, sizeof(temp), PSTR("homeassistant/sensor/%s/boiler/config"), Mqtt::base().c_str()); - Mqtt::publish_ha(temp, doc.as()); // publish the config payload with retain flag - - Mqtt::register_mqtt_ha_binary_sensor(F_(tapwaterActive), device_type(), "tapwater_active"); - Mqtt::register_mqtt_ha_binary_sensor(F_(heatingActive), device_type(), "heating_active"); - - // main - if (Helpers::hasValue(serviceCodeNumber_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(serviceCodeNumber), device_type(), "serviceCodeNumber", nullptr, F_(iconpower)); - } - if (Helpers::hasValue(selFlowTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(selFlowTemp), device_type(), "selFlowTemp", F_(degrees), F_(iconcruise)); - } - if (Helpers::hasValue(selBurnPow_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(selBurnPow), device_type(), "selBurnPow", F_(percent), F_(iconpercent)); - } - if (Helpers::hasValue(curBurnPow_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(curBurnPow), device_type(), "curBurnPow", F_(percent), F_(iconfire)); - } - if (Helpers::hasValue(outdoorTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(outdoorTemp), device_type(), "outdoorTemp", F_(degrees), F_(iconexport)); - } - if (Helpers::hasValue(curFlowTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(curFlowTemp), device_type(), "curFlowTemp", F_(degrees), F_(iconwatertemp)); - } - if (Helpers::hasValue(retTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(retTemp), device_type(), "retTemp", F_(degrees), F_(iconwatertemp)); - } - if (Helpers::hasValue(heatingPump_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(heatingPump), device_type(), "heatingPump", nullptr, F_(iconpump)); - } - if (Helpers::hasValue(burnGas_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(burnGas), device_type(), "burnGas", nullptr, F_(iconfire)); - } - if (Helpers::hasValue(fanWork_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(fanWork), device_type(), "fanWork", nullptr, F_(iconfan)); - } - if (Helpers::hasValue(heatingActivated_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(heatingActivated), device_type(), "heatingActivated", nullptr, nullptr); - } - if (Helpers::hasValue(heatingTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(heatingTemp), device_type(), "heatingTemp", F_(degrees), F_(iconwatertemp)); - } - if (Helpers::hasValue(burnMinPeriod_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(burnMinPeriod), device_type(), "burnMinPeriod", F_(min), nullptr); - } - if (Helpers::hasValue(burnMinPower_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(burnMinPower), device_type(), "burnMinPower", F_(percent), F_(iconpercent)); - } - if (Helpers::hasValue(burnMaxPower_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(burnMaxPower), device_type(), "burnMaxPower", F_(percent), F_(iconpercent)); - } - if (Helpers::hasValue(boilHystOn_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(boilHystOn), device_type(), "boilHystOn", F_(degrees), F_(iconwatertemp)); - } - if (Helpers::hasValue(boilHystOff_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(boilHystOff), device_type(), "boilHystOff", F_(degrees), F_(iconwatertemp)); - } - if (Helpers::hasValue(setFlowTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(setFlowTemp), device_type(), "setFlowTemp", F_(degrees), F_(iconwatertemp)); - } - if (Helpers::hasValue(setBurnPow_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(setBurnPow), device_type(), "setBurnPow", F_(percent), F_(iconpercent)); - } - if (Helpers::hasValue(burnStarts_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(burnStarts), device_type(), "burnStarts", nullptr, nullptr); - } - if (Helpers::hasValue(burnWorkMin_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(burnWorkMin), device_type(), "burnWorkMin", F_(min), nullptr); - } - // values should be sent if hasValues checks to false, but I see MQTT messages for non iRT sensors, so avoid sending it by tx-Mode - if (EMSbus::tx_mode() <= EMS_TXMODE_HW) { - if (Helpers::hasValue(heatingPumpMod_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(heatingPumpMod), device_type(), "heatingPumpMod", F_(percent), F_(iconpercent)); + if (mqtt_ha_config_ == 0) { + // Create the Master device + DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_HA_CONFIG); + //StaticJsonDocument doc; + doc["name"] = FJSON("Service Code"); + doc["uniq_id"] = FJSON("boiler"); + doc["ic"] = FJSON("mdi:home-thermometer-outline"); + + char temp[128]; + snprintf_P(temp, sizeof(temp), PSTR("%s/boiler_data"), Mqtt::base().c_str()); + doc["stat_t"] = temp; + + doc["val_tpl"] = FJSON("{{value_json.serviceCode}}"); + JsonObject dev = doc.createNestedObject("dev"); + snprintf_P(temp, sizeof(temp), PSTR("%s Boiler"), Mqtt::base().c_str()); + dev["name"] = temp; + dev["sw"] = EMSESP_APP_VERSION; + dev["mf"] = brand_to_string(); + dev["mdl"] = name(); + JsonArray ids = dev.createNestedArray("ids"); + snprintf_P(temp, sizeof(temp), PSTR("%s-boiler"), Mqtt::base().c_str()); + ids.add(temp); + snprintf_P(temp, sizeof(temp), PSTR("homeassistant/sensor/%s/boiler/config"), Mqtt::base().c_str()); + LOG_DEBUG(F("[DEBUG] Json memoryUsage:%d, measureJson:%d"), doc.memoryUsage(), measureJson(doc)); + Mqtt::publish_ha(temp, doc.as()); // publish the config payload with retain flag + + Mqtt::register_mqtt_ha_binary_sensor(F_(tapwaterActive), device_type(), "tapwater_active"); + Mqtt::register_mqtt_ha_binary_sensor(F_(heatingActive), device_type(), "heating_active"); + + // main + if (Helpers::hasValue(serviceCodeNumber_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(serviceCodeNumber), device_type(), "serviceCodeNumber", nullptr, F_(iconpower)); + } + if (Helpers::hasValue(selFlowTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(selFlowTemp), device_type(), "selFlowTemp", F_(degrees), F_(iconcruise)); } - if (Helpers::hasValue(heatingPump2Mod_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(heatingPump2Mod), device_type(), "heatingPump2Mod", F_(percent), F_(iconpercent)); + if (Helpers::hasValue(selBurnPow_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(selBurnPow), device_type(), "selBurnPow", F_(percent), F_(iconpercent)); } - if (Helpers::hasValue(switchTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(switchTemp), device_type(), "switchTemp", F_(degrees), F_(iconwatertemp)); + if (Helpers::hasValue(curBurnPow_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(curBurnPow), device_type(), "curBurnPow", F_(percent), F_(iconfire)); } - if (Helpers::hasValue(sysPress_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(sysPress), device_type(), "sysPress", F_(bar), nullptr); + if (Helpers::hasValue(outdoorTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(outdoorTemp), device_type(), "outdoorTemp", F_(degrees), F_(iconexport)); } - if (Helpers::hasValue(boilTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(boilTemp), device_type(), "boilTemp", F_(degrees), nullptr); + if (Helpers::hasValue(curFlowTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(curFlowTemp), device_type(), "curFlowTemp", F_(degrees), F_(iconwatertemp)); } - if (Helpers::hasValue(flameCurr_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(flameCurr), device_type(), "flameCurr", F_(uA), F_(iconflash)); + if (Helpers::hasValue(retTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(retTemp), device_type(), "retTemp", F_(degrees), F_(iconwatertemp)); } - if (Helpers::hasValue(ignWork_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(ignWork), device_type(), "ignWork", nullptr, F_(iconflash)); + if (Helpers::hasValue(heatingPump_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(heatingPump), device_type(), "heatingPump", nullptr, F_(iconpump)); } - if (Helpers::hasValue(exhaustTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(exhaustTemp), device_type(), "exhaustTemp", F_(degrees), F_(iconwatertemp)); + if (Helpers::hasValue(burnGas_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(burnGas), device_type(), "burnGas", nullptr, F_(iconfire)); } - if (Helpers::hasValue(pumpModMax_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(pumpModMax), device_type(), "pumpModMax", F_(percent), F_(iconpercent)); + if (Helpers::hasValue(fanWork_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(fanWork), device_type(), "fanWork", nullptr, F_(iconfan)); } - if (Helpers::hasValue(pumpModMin_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(pumpModMin), device_type(), "pumpModMin", F_(percent), F_(iconpercent)); + if (Helpers::hasValue(heatingActivated_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(heatingActivated), device_type(), "heatingActivated", nullptr, nullptr); } - if (Helpers::hasValue(pumpDelay_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(pumpDelay), device_type(), "pumpDelay", F_(min), nullptr); + if (Helpers::hasValue(heatingTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(heatingTemp), device_type(), "heatingTemp", F_(degrees), F_(iconwatertemp)); } - if (Helpers::hasValue(heatWorkMin_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(heatWorkMin), device_type(), "heatWorkMin", F_(min), nullptr); + if (Helpers::hasValue(burnMinPeriod_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(burnMinPeriod), device_type(), "burnMinPeriod", F_(min), nullptr); } - if (Helpers::hasValue(UBAuptime_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(UBAuptime), device_type(), "UBAuptime", F_(min), nullptr); + if (Helpers::hasValue(burnMinPower_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(burnMinPower), device_type(), "burnMinPower", F_(percent), F_(iconpercent)); } - if (Helpers::hasValue(maintenanceMessage_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(maintenanceMessage), device_type(), "maintenanceMessage", nullptr, nullptr); + if (Helpers::hasValue(burnMaxPower_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(burnMaxPower), device_type(), "burnMaxPower", F_(percent), F_(iconpercent)); + } + } + else if (mqtt_ha_config_ == 1) { + if (Helpers::hasValue(boilHystOn_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(boilHystOn), device_type(), "boilHystOn", F_(degrees), F_(iconwatertemp)); } - if (Helpers::hasValue(maintenanceType_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(maintenance), device_type(), "maintenance", nullptr, nullptr); + if (Helpers::hasValue(boilHystOff_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(boilHystOff), device_type(), "boilHystOff", F_(degrees), F_(iconwatertemp)); } - // optional etra values for date and time if not handled by maintenance - // if (Helpers::hasValue(maintenanceTime_)) { - // Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(maintenanceTime), device_type(), "maintenanceTime", F_(hours), nullptr); - // } - // if (strlen(maintenanceDate_) > 0) { - // Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(maintenanceDate), device_type(), "maintenanceDate", nullptr, nullptr); - // } - if (Helpers::hasValue(mixerTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(mixerTemp), device_type(), "mixerTemp", F_(degrees), nullptr); + if (Helpers::hasValue(setFlowTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(setFlowTemp), device_type(), "setFlowTemp", F_(degrees), F_(iconwatertemp)); } - if (Helpers::hasValue(tankMiddleTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(tankMiddleTemp), device_type(), "tankMiddleTemp", F_(degrees), nullptr); + if (Helpers::hasValue(setBurnPow_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(setBurnPow), device_type(), "setBurnPow", F_(percent), F_(iconpercent)); + } + if (Helpers::hasValue(burnStarts_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(burnStarts), device_type(), "burnStarts", nullptr, nullptr); + } + if (Helpers::hasValue(burnWorkMin_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(burnWorkMin), device_type(), "burnWorkMin", F_(min), nullptr); + } + } + else if (mqtt_ha_config_ == 2) { + // values should be sent if hasValues checks to false, but I see MQTT messages for non iRT sensors, so avoid sending it by tx-Mode + if (EMSbus::tx_mode() <= EMS_TXMODE_HW) { + if (Helpers::hasValue(heatingPumpMod_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(heatingPumpMod), device_type(), "heatingPumpMod", F_(percent), F_(iconpercent)); + } + if (Helpers::hasValue(heatingPump2Mod_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(heatingPump2Mod), device_type(), "heatingPump2Mod", F_(percent), F_(iconpercent)); + } + if (Helpers::hasValue(switchTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(switchTemp), device_type(), "switchTemp", F_(degrees), F_(iconwatertemp)); + } + if (Helpers::hasValue(sysPress_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(sysPress), device_type(), "sysPress", F_(bar), nullptr); + } + if (Helpers::hasValue(boilTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(boilTemp), device_type(), "boilTemp", F_(degrees), nullptr); + } + if (Helpers::hasValue(flameCurr_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(flameCurr), device_type(), "flameCurr", F_(uA), F_(iconflash)); + } + if (Helpers::hasValue(ignWork_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(ignWork), device_type(), "ignWork", nullptr, F_(iconflash)); + } + if (Helpers::hasValue(exhaustTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(exhaustTemp), device_type(), "exhaustTemp", F_(degrees), F_(iconwatertemp)); + } + if (Helpers::hasValue(pumpModMax_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(pumpModMax), device_type(), "pumpModMax", F_(percent), F_(iconpercent)); + } + if (Helpers::hasValue(pumpModMin_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(pumpModMin), device_type(), "pumpModMin", F_(percent), F_(iconpercent)); + } + if (Helpers::hasValue(pumpDelay_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(pumpDelay), device_type(), "pumpDelay", F_(min), nullptr); + } + if (Helpers::hasValue(heatWorkMin_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(heatWorkMin), device_type(), "heatWorkMin", F_(min), nullptr); + } + if (Helpers::hasValue(UBAuptime_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(UBAuptime), device_type(), "UBAuptime", F_(min), nullptr); + } + if (Helpers::hasValue(maintenanceMessage_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(maintenanceMessage), device_type(), "maintenanceMessage", nullptr, nullptr); + } + if (Helpers::hasValue(maintenanceType_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(maintenance), device_type(), "maintenance", nullptr, nullptr); + } + // optional etra values for date and time if not handled by maintenance + // if (Helpers::hasValue(maintenanceTime_)) { + // Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(maintenanceTime), device_type(), "maintenanceTime", F_(hours), nullptr); + // } + // if (strlen(maintenanceDate_) > 0) { + // Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(maintenanceDate), device_type(), "maintenanceDate", nullptr, nullptr); + // } + if (Helpers::hasValue(mixerTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(mixerTemp), device_type(), "mixerTemp", F_(degrees), nullptr); + } + if (Helpers::hasValue(tankMiddleTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, nullptr, F_(tankMiddleTemp), device_type(), "tankMiddleTemp", F_(degrees), nullptr); + } } } - // information for heatpumps - if (model() == EMSdevice::EMS_DEVICE_FLAG_HEATPUMP) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(upTimeControl), device_type(), "upTimeControl", F_(min), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(upTimeCompHeating), device_type(), "upTimeCompHeating", F_(min), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(upTimeCompCooling), device_type(), "upTimeCompCooling", F_(min), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(upTimeCompWw), device_type(), "upTimeCompWw", F_(min), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(heatingStarts), device_type(), "heatingStarts", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(coolingStarts), device_type(), "coolingStarts_", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(wWStarts2), device_type(), "wWStarts2", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgConsTotal), device_type(), "nrgConsTotal", F_(kwh), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(auxElecHeatNrgConsTotal), device_type(), "auxElecHeatNrgConsTotal_", F_(kwh), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(auxElecHeatNrgConsHeating), device_type(), "auxElecHeatNrgConsHeating", F_(kwh), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(auxElecHeatNrgConsDHW), device_type(), "auxElecHeatNrgConsDHW", F_(kwh), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgConsCompTotal), device_type(), "nrgConsCompTotal", F_(kwh), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgConsCompHeating), device_type(), "nrgConsCompHeating", F_(kwh), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgConsCompWw), device_type(), "nrgConsCompWw", F_(kwh), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgConsCompCooling), device_type(), "nrgConsCompCooling", F_(kwh), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgSuppTotal), device_type(), "nrgSuppTotal_", F_(kwh), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgSuppHeating), device_type(), "nrgSuppHeating", F_(kwh), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgSuppWw), device_type(), "nrgSuppWw", F_(kwh), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgSuppCooling), device_type(), "nrgSuppCooling", F_(kwh), nullptr); + else if (mqtt_ha_config_ == 3) { + // information for heatpumps + if (model() == EMSdevice::EMS_DEVICE_FLAG_HEATPUMP) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(upTimeControl), device_type(), "upTimeControl", F_(min), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(upTimeCompHeating), device_type(), "upTimeCompHeating", F_(min), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(upTimeCompCooling), device_type(), "upTimeCompCooling", F_(min), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(upTimeCompWw), device_type(), "upTimeCompWw", F_(min), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(heatingStarts), device_type(), "heatingStarts", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(coolingStarts), device_type(), "coolingStarts_", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(wWStarts2), device_type(), "wWStarts2", nullptr, nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgConsTotal), device_type(), "nrgConsTotal", F_(kwh), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(auxElecHeatNrgConsTotal), device_type(), "auxElecHeatNrgConsTotal_", F_(kwh), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(auxElecHeatNrgConsHeating), device_type(), "auxElecHeatNrgConsHeating", F_(kwh), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(auxElecHeatNrgConsDHW), device_type(), "auxElecHeatNrgConsDHW", F_(kwh), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgConsCompTotal), device_type(), "nrgConsCompTotal", F_(kwh), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgConsCompHeating), device_type(), "nrgConsCompHeating", F_(kwh), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgConsCompWw), device_type(), "nrgConsCompWw", F_(kwh), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgConsCompCooling), device_type(), "nrgConsCompCooling", F_(kwh), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgSuppTotal), device_type(), "nrgSuppTotal_", F_(kwh), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgSuppHeating), device_type(), "nrgSuppHeating", F_(kwh), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgSuppWw), device_type(), "nrgSuppWw", F_(kwh), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(nrgSuppCooling), device_type(), "nrgSuppCooling", F_(kwh), nullptr); + } } // Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(maintenanceMessage), device_type(), "maintenanceMessage", nullptr, nullptr); // Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(maintenance), device_type(), "maintenance", nullptr, nullptr); // Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(maintenanceTime), device_type(), "maintenanceTime", F_(hours), nullptr); // Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(maintenanceDate), device_type(), "maintenanceDate", nullptr, nullptr); - mqtt_ha_config_ = true; // done + mqtt_ha_config_++; // done } // create the config topics for Home Assistant MQTT Discovery @@ -335,92 +344,97 @@ void Boiler::register_mqtt_ha_config_ww() { return; } - // ww - if (Helpers::hasValue(wWSelTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWSelTemp), device_type(), "wWSelTemp", F_(degrees), F_(iconcruise)); - } - if (Helpers::hasValue(wWSetTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWSetTemp), device_type(), "wWSetTemp", F_(degrees), F_(iconwatertemp)); - } - if (Helpers::hasValue(wWCurTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWCurTemp), device_type(), "wWCurTemp", F_(degrees), F_(iconwatertemp)); - } - if (Helpers::hasValue(ww3wayValve_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(ww3wayValve), device_type(), "ww3wayValve", nullptr, F_(iconvalve)); - } - if (Helpers::hasValue(wWActivated_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWActivated), device_type(), "wWActivated", nullptr, nullptr); - } - if (Helpers::hasValue(wWActive_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWActive), device_type(), "wWActive", nullptr, nullptr); - } - // values should be sent if hasValues checks to false, but I see MQTT messages for non iRT sensors, so avoid sending it by tx-Mode - if (EMSbus::tx_mode() <= EMS_TXMODE_HW) { - if (Helpers::hasValue(wWDisinfectionTemp_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWDisinfectionTemp), device_type(), "wWDisinfectionTemp", F_(degrees), F_(iconwatertemp)); - } - if (Helpers::hasValue(wWType_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWType), device_type(), "wWType", nullptr, nullptr); - } - if (Helpers::hasValue(wWChargeType_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWChargeType), device_type(), "wWChargeType", nullptr, nullptr); - } - if (Helpers::hasValue(wWCircPump_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWCircPump), device_type(), "wWCircPump", nullptr, nullptr); - } - if (Helpers::hasValue(wWCircPumpMode_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWCircPumpMode), device_type(), "wWCircPumpMode", nullptr, nullptr); - } - if (Helpers::hasValue(wWCirc_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWCirc), device_type(), "wWCirc", nullptr, nullptr); - } - if (Helpers::hasValue(wWCurTemp2_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWCurTemp2), device_type(), "wWCurTemp2", F_(degrees), F_(iconwatertemp)); - } - if (Helpers::hasValue(wWCurFlow_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWCurFlow), device_type(), "wWCurFlow", F("l/min"), F_(iconwatertemp)); - } - if (Helpers::hasValue(wWStorageTemp1_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWStorageTemp1), device_type(), "wWStorageTemp1", F_(degrees), F_(iconwatertemp)); - } - if (Helpers::hasValue(wWStorageTemp2_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWStorageTemp2), device_type(), "wWStorageTemp2", F_(degrees), F_(iconwatertemp)); - } - if (Helpers::hasValue(wWOneTime_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWOneTime), device_type(), "wWOneTime", nullptr, nullptr); - } - if (Helpers::hasValue(wWDisinfecting_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWDisinfecting), device_type(), "wWDisinfecting", nullptr, nullptr); - } - if (Helpers::hasValue(wWCharging_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWCharging), device_type(), "wWCharging", nullptr, nullptr); + if (mqtt_ha_config_ww_ == 0) { + // ww + if (Helpers::hasValue(wWSelTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWSelTemp), device_type(), "wWSelTemp", F_(degrees), F_(iconcruise)); } - if (Helpers::hasValue(wWRecharging_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWRecharging), device_type(), "wWRecharging", nullptr, nullptr); + if (Helpers::hasValue(wWSetTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWSetTemp), device_type(), "wWSetTemp", F_(degrees), F_(iconwatertemp)); } - if (Helpers::hasValue(wWTempOK_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWTempOK), device_type(), "wWTempOK", nullptr, nullptr); + if (Helpers::hasValue(wWCurTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWCurTemp), device_type(), "wWCurTemp", F_(degrees), F_(iconwatertemp)); } - if (Helpers::hasValue(wWSetPumpPower_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWSetPumpPower), device_type(), "wWSetPumpPower", F_(percent), F_(iconpump)); + if (Helpers::hasValue(ww3wayValve_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(ww3wayValve), device_type(), "ww3wayValve", nullptr, F_(iconvalve)); } - if (Helpers::hasValue(wWStarts_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWStarts), device_type(), "wWStarts", nullptr, nullptr); + if (Helpers::hasValue(wWActivated_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWActivated), device_type(), "wWActivated", nullptr, nullptr); } - if (Helpers::hasValue(wWWorkM_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWWorkM), device_type(), "wWWorkM", F_(min), nullptr); + if (Helpers::hasValue(wWActive_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWActive), device_type(), "wWActive", nullptr, nullptr); } - if (Helpers::hasValue(wWMaxPower_)) { - Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWMaxPower), device_type(), "wWMaxPower", F_(percent), nullptr); + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_info), F_(gasReading), device_type(), "gasReading", nullptr, nullptr); + } + else if (mqtt_ha_config_ww_ == 1) { + // values should be sent if hasValues checks to false, but I see MQTT messages for non iRT sensors, so avoid sending it by tx-Mode + if (EMSbus::tx_mode() <= EMS_TXMODE_HW) { + if (Helpers::hasValue(wWDisinfectionTemp_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWDisinfectionTemp), device_type(), "wWDisinfectionTemp", F_(degrees), F_(iconwatertemp)); + } + if (Helpers::hasValue(wWType_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWType), device_type(), "wWType", nullptr, nullptr); + } + if (Helpers::hasValue(wWChargeType_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWChargeType), device_type(), "wWChargeType", nullptr, nullptr); + } + if (Helpers::hasValue(wWCircPump_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWCircPump), device_type(), "wWCircPump", nullptr, nullptr); + } + if (Helpers::hasValue(wWCircPumpMode_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWCircPumpMode), device_type(), "wWCircPumpMode", nullptr, nullptr); + } + if (Helpers::hasValue(wWCirc_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWCirc), device_type(), "wWCirc", nullptr, nullptr); + } + if (Helpers::hasValue(wWCurTemp2_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWCurTemp2), device_type(), "wWCurTemp2", F_(degrees), F_(iconwatertemp)); + } + if (Helpers::hasValue(wWCurFlow_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWCurFlow), device_type(), "wWCurFlow", F("l/min"), F_(iconwatertemp)); + } + if (Helpers::hasValue(wWStorageTemp1_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWStorageTemp1), device_type(), "wWStorageTemp1", F_(degrees), F_(iconwatertemp)); + } + if (Helpers::hasValue(wWStorageTemp2_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWStorageTemp2), device_type(), "wWStorageTemp2", F_(degrees), F_(iconwatertemp)); + } + if (Helpers::hasValue(wWOneTime_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWOneTime), device_type(), "wWOneTime", nullptr, nullptr); + } + if (Helpers::hasValue(wWDisinfecting_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWDisinfecting), device_type(), "wWDisinfecting", nullptr, nullptr); + } + if (Helpers::hasValue(wWCharging_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWCharging), device_type(), "wWCharging", nullptr, nullptr); + } + if (Helpers::hasValue(wWRecharging_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWRecharging), device_type(), "wWRecharging", nullptr, nullptr); + } + if (Helpers::hasValue(wWTempOK_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWTempOK), device_type(), "wWTempOK", nullptr, nullptr); + } + if (Helpers::hasValue(wWSetPumpPower_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWSetPumpPower), device_type(), "wWSetPumpPower", F_(percent), F_(iconpump)); + } + if (Helpers::hasValue(wWStarts_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWStarts), device_type(), "wWStarts", nullptr, nullptr); + } + if (Helpers::hasValue(wWWorkM_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWWorkM), device_type(), "wWWorkM", F_(min), nullptr); + } + if (Helpers::hasValue(wWMaxPower_)) { + Mqtt::register_mqtt_ha_sensor(nullptr, F_(mqtt_suffix_ww), F_(wWMaxPower), device_type(), "wWMaxPower", F_(percent), nullptr); + } } } - mqtt_ha_config_ww_ = true; // done + mqtt_ha_config_ww_++; // done } // send stuff to the Web UI void Boiler::device_info_web(JsonArray & root, uint8_t & part) { // fetch the values into a JSON document - DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_LARGE); + DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_LARGE_DYN); //StaticJsonDocument doc; JsonObject json = doc.to(); if (part == 0) { @@ -502,6 +516,7 @@ void Boiler::device_info_web(JsonArray & root, uint8_t & part) { create_value_json(root, F("wWSetPumpPower"), nullptr, F_(wWSetPumpPower), F_(percent), json); create_value_json(root, F("wWStarts"), nullptr, F_(wWStarts), nullptr, json); create_value_json(root, F("wWWorkM"), nullptr, F_(wWWorkM), nullptr, json); + create_value_json(root, F("gasReading"), nullptr, F_(gasReading), F_(meter3), json); } else if (part == 2) { part = 0; // no more parts if (!export_values_info(json, true)) { // append info values @@ -661,6 +676,8 @@ bool Boiler::export_values_ww(JsonObject & json, const bool textformat) { json["wWMaxPower"] = wWMaxPower_; } + json["gasReading"] = (float)(emsesp::System::gasReading_/emsesp::System::convFactor_/4); + // Warm Water active time Helpers::json_time(json, "wWWorkM", wWWorkM_, textformat); @@ -1002,24 +1019,24 @@ void Boiler::publish_values(JsonObject & json, bool force) { LOG_DEBUG(F("[DEBUG] MQTT format: %d, ha_config: %d, ha_config_ww: %d, uptime: %d, tx_delay: %d, force: %d"), Mqtt::mqtt_format(), mqtt_ha_config_,mqtt_ha_config_ww_,uuid::get_uptime_sec(),EMSESP::tx_delay(), force); if (Mqtt::mqtt_format() == Mqtt::Format::HA) { if (force) { - mqtt_ha_config_ = false; - mqtt_ha_config_ww_ = false; + mqtt_ha_config_ = 0; + mqtt_ha_config_ww_ = 0; } // register ww in next cycle if both unregistered - if (!mqtt_ha_config_ && uuid::get_uptime_sec() > (EMSESP::tx_delay() + 60u)) { + if ((mqtt_ha_config_ < 3) && uuid::get_uptime_sec() > (EMSESP::tx_delay() + 60u +(uint8_t)(mqtt_ha_config_*10))) { LOG_DEBUG(F("[DEBUG] register MQTT HA config")); register_mqtt_ha_config(); return; - } else if (!mqtt_ha_config_ww_ && uuid::get_uptime_sec() > (EMSESP::tx_delay() + 60u)) { + } else if ((mqtt_ha_config_ww_ < 2) && uuid::get_uptime_sec() > (EMSESP::tx_delay() + 60u+(uint8_t)(mqtt_ha_config_ww_*10))) { LOG_DEBUG(F("[DEBUG] register MQTT HA config ww")); register_mqtt_ha_config_ww(); return; } } - DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_LARGE); - //StaticJsonDocument doc; + DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_MEDIUM); + //StaticJsonDocument doc; JsonObject json_data = doc.to(); if (export_values_main(json_data)) { Mqtt::publish(F("boiler_data"), json_data); @@ -1189,7 +1206,7 @@ void Boiler::process_IRTGetActBurnerPower(std::shared_ptr telegr /* 83 C3 79 E1 00 * 83 C3 79 E1 ss * ss - 0xA0 - if burner off - * ss - 0x00 - 0xFF burner power: ss * 0.25 + 37 */ + * ss - 0x00 - 0xFF burner power: ss * 0.25 + 30 */ uint8_t temp; changed_ |= telegram->read_value(temp, 4); if ((temp==0xA0) && (heatingActive_==0)) diff --git a/src/devices/boiler.h b/src/devices/boiler.h index 30e74ebc..bb07ec7a 100644 --- a/src/devices/boiler.h +++ b/src/devices/boiler.h @@ -60,8 +60,8 @@ class Boiler : public EMSdevice { bool export_values_info(JsonObject & doc, const bool textformat = false); bool changed_ = false; - bool mqtt_ha_config_ = false; // HA MQTT Discovery - bool mqtt_ha_config_ww_ = false; // HA MQTT Discovery + uint8_t mqtt_ha_config_ = 0; // HA MQTT Discovery + uint8_t mqtt_ha_config_ww_ = 0; // HA MQTT Discovery static constexpr uint8_t EMS_TYPE_UBAParameterWW = 0x33; static constexpr uint8_t EMS_TYPE_UBAFunctionTest = 0x1D; diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index 7dcf7610..39c90a22 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -197,7 +197,7 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i // prepare data for Web UI void Thermostat::device_info_web(JsonArray & root, uint8_t & part) { - DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_LARGE); + DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_LARGE_DYN); //StaticJsonDocument doc; JsonObject json = doc.to(); if (part == 0) { @@ -334,7 +334,7 @@ void Thermostat::publish_values(JsonObject & json, bool force) { } } - DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_LARGE); + DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_LARGE_DYN); //StaticJsonDocument doc; JsonObject json_data = doc.to(); diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 4979c7c4..6ba1105c 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -411,8 +411,8 @@ void EMSESP::publish_all_loop() { // special case for Mixer units, since we want to bundle all devices together into one payload void EMSESP::publish_device_values(uint8_t device_type, bool force) { if (device_type == EMSdevice::DeviceType::MIXER && Mqtt::mqtt_format() != Mqtt::Format::SINGLE) { - DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_LARGE); - // StaticJsonDocument doc; + DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_LARGE_DYN); + //StaticJsonDocument doc; JsonObject json = doc.to(); for (const auto & emsdevice : emsdevices) { if (emsdevice && (emsdevice->device_type() == device_type)) { diff --git a/src/emsesp.h b/src/emsesp.h index e5305b16..febd3588 100644 --- a/src/emsesp.h +++ b/src/emsesp.h @@ -58,7 +58,8 @@ #define EMSESP_MAX_JSON_SIZE_LARGE 1924 // for large json docs from ems devices, like boiler or thermostat data, using StaticJsonDocument #define EMSESP_MAX_JSON_SIZE_MEDIUM_DYN 1024 // for large json docs, using DynamicJsonDocument #define EMSESP_MAX_JSON_SIZE_LARGE_DYN 2048 // for very large json docs, using DynamicJsonDocument -#define EMSESP_MAX_JSON_SIZE_MAX_DYN 4096 // for very very large json docs, using DynamicJsonDocument +#define EMSESP_MAX_JSON_SIZE_MAX_DYN 3072 // for very very large json docs, using DynamicJsonDocument +#define EMSESP_MAX_JSON_SIZE_SMAX_DYN 4096 // for very super large json docs, using DynamicJsonDocument /* #define EMSESP_MAX_JSON_SIZE_HA_CONFIG min(384,ESP.getMaxFreeBlockSize() - 512) // for small HA config payloads, using StaticJsonDocument #define EMSESP_MAX_JSON_SIZE_SMALL min(256,ESP.getMaxFreeBlockSize() - 512) // for smaller json docs, using StaticJsonDocument #define EMSESP_MAX_JSON_SIZE_MEDIUM min(768,ESP.getMaxFreeBlockSize() - 512) // for medium json docs from ems devices, using StaticJsonDocument diff --git a/src/locale_EN.h b/src/locale_EN.h index e9a6af29..9b84faa2 100644 --- a/src/locale_EN.h +++ b/src/locale_EN.h @@ -142,6 +142,7 @@ MAKE_PSTR(min_boiler_wh_fmt, "Boiler minimum power = %dWh") MAKE_PSTR(max_boiler_wh_fmt, "Boiler maximum power = %dWh") MAKE_PSTR(gas_meter_reading_fmt, "Gas meter = %dm³") MAKE_PSTR(conv_factor_fmt, "Conversion factor m³<-> Wh = %d") +MAKE_PSTR(gas_meter_reading, "Gas meter reading") // status MAKE_PSTR(wifirssi, "WiFi RSSI") diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 5474ec74..3301b0d2 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -662,13 +662,14 @@ void Mqtt::publish_ha(const std::string & topic, const JsonObject & payload) { #if defined(EMSESP_STANDALONE) LOG_DEBUG(F("Publishing HA topic=%s, payload=%s"), topic.c_str(), payload_text.c_str()); #else - LOG_DEBUG(F("Publishing HA topic %s"), topic.c_str()); + LOG_DEBUG(F("Publishing HA topic %s size %d"), topic.c_str(), payload_text.length()); #endif - -#if defined(ESP32) + LOG_DEBUG(F("%d queued messages"), mqtt_messages_.size()); + queue_publish_message(topic, payload_text, true); // with retain true +/* #if defined(ESP32) bool queued = true; // queue MQTT publish #else - bool queued = false; // publish immediately + bool queued = true; // queue MQTT publish if enough space on should not forced #endif // if MQTT is not connected, then we have to queue the msg until the MQTT is online @@ -682,12 +683,13 @@ void Mqtt::publish_ha(const std::string & topic, const JsonObject & payload) { } // send immediately and then wait a while - if (!mqttClient_->publish(topic.c_str(), 0, true, payload_text.c_str())) { + if (!mqttClient_->publish(topic.c_str(), 0, true, payload_text.c_str(), payload_text.size())) { LOG_ERROR(F("Failed to publish topic %s"), topic.c_str()); } - + EspClass::wdtFeed(); delay(MQTT_HA_PUBLISH_DELAY); // enough time to send the short message out -} + yield(); + */} // take top from queue and perform the publish or subscribe action // assumes there is an MQTT connection diff --git a/src/mqtt.h b/src/mqtt.h index f5a5cf05..940ddba2 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -183,7 +183,7 @@ class Mqtt { #elif defined(ESP32) static constexpr size_t MAX_MQTT_MESSAGES = 100; // size of queue #else - static constexpr size_t MAX_MQTT_MESSAGES = 20; // size of queue + static constexpr size_t MAX_MQTT_MESSAGES = 25; // size of queue #endif static constexpr uint32_t MQTT_PUBLISH_WAIT = 100; // delay between sending publishes, to account for large payloads diff --git a/src/system.cpp b/src/system.cpp index 2076da5a..69b404ce 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -332,14 +332,17 @@ void System::loop() { if (syslog_enabled_) { syslog_.loop(); } + yield(); myPButton_.check(); // check button press - + yield(); led_monitor(); // check status and report back using the LED + yield(); system_check(); // check system health + yield(); if (analog_enabled_) { measure_analog(); } - + yield(); // send out heartbeat uint32_t currentMillis = uuid::get_uptime(); if (!last_heartbeat_ || (currentMillis - last_heartbeat_ > SYSTEM_HEARTBEAT_INTERVAL)) { @@ -349,7 +352,8 @@ void System::loop() { #if defined(EMSESP_DEBUG) LOG_INFO(F("last burner power %d, current burner power %d"), last_burnPower_, EMSESP::current_burn_pow()); #endif - if (!last_burnPower_) { + yield(); + if (gasReading_ == 0) { EMSESP::webSettingsService.read([&](WebSettings & settings) { convFactor_ = settings.conv_factor; gasReading_ = settings.gas_meter_reading * convFactor_*4; @@ -360,6 +364,7 @@ void System::loop() { else { gasReading_ = gasReading_+ (last_burnPower_ + EMSESP::current_burn_pow())*maxWhPower_ / 3000.0; } + yield(); last_burnPower_ = EMSESP::current_burn_pow(); if (gasReading_ - storedGasReading_ > convFactor_*4) { EMSESP::webSettingsService.update( @@ -369,6 +374,7 @@ void System::loop() { }, "local"); storedGasReading_ = gasReading_; + yield(); EMSESP::webSettingsService.save(); // local settings } @@ -436,8 +442,8 @@ void System::send_heartbeat() { return; } } - DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_MEDIUM); - //StaticJsonDocument doc; + DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_MEDIUM); + //StaticJsonDocument doc; uint8_t ems_status = EMSESP::bus_status(); if (ems_status == EMSESP::BUS_STATUS_TX_ERRORS) { @@ -469,8 +475,7 @@ void System::send_heartbeat() { if (analog_enabled_) { doc["adc"] = analog_; } - doc["gasReading"] = (float)gasReading_/convFactor_/4; - + doc["gasReading"] = (float)(gasReading_/convFactor_/4); Mqtt::publish(F("heartbeat"), doc.as()); // send to MQTT with retain off. This will add to MQTT queue. } @@ -883,7 +888,7 @@ bool System::check_upgrade() { bool failed = false; File file; JsonObject network, general, mqtt, custom_settings; - DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_LARGE); + DynamicJsonDocument doc(EMSESP_MAX_JSON_SIZE_LARGE_DYN); //StaticJsonDocument doc; // open the system settings: diff --git a/src/system.h b/src/system.h index 59572d59..488be665 100644 --- a/src/system.h +++ b/src/system.h @@ -73,6 +73,8 @@ class System { bool check_upgrade(); void send_heartbeat(); + static float gasReading_; // calculated gas meter reading + static uint16_t convFactor_; // convertion factor m³<->Wh private: static uuid::log::Logger logger_; @@ -124,11 +126,9 @@ class System { static uint8_t led_gpio_; static bool syslog_enabled_; static bool analog_enabled_; - static float gasReading_; // calculated gas meter reading static uint32_t maxWhPower_; // max boiler power in Wh static uint32_t storedGasReading_; // gas meter reading stored in SPIFFS uint32_t last_burnPower_ = 0; - static uint16_t convFactor_; // convertion factor m³<->Wh bool mqtt_ha_status_config = false; // HA MQTT Discovery }; diff --git a/src/test/test.cpp b/src/test/test.cpp index 36fdadf8..c94579f3 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -367,6 +367,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) { shell.invoke_command("show"); DynamicJsonDocument doc(500); + // StaticJsonDocument<500> doc; JsonObject root = doc.to(); EMSESP::device_info_web(2, root); // show thermostat. use 1 for boiler serializeJsonPretty(doc, shell); diff --git a/src/version.h b/src/version.h index 77aab5c1..a33d96d4 100644 --- a/src/version.h +++ b/src/version.h @@ -1,2 +1,2 @@ -#define EMSESP_APP_VERSION "2.3.1b1" +#define EMSESP_APP_VERSION "2.3.1b3" #define EMSESP_PLATFORM "ESP8266"