From f766a6801113036c7d310061b2eb56531246c4b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Bo=CC=88hm?= Date: Wed, 11 Sep 2024 16:10:51 +0200 Subject: [PATCH] don't republish MQTT powermeter data to MQTT --- include/PowerMeterMqtt.h | 4 +++- src/PowerMeter.cpp | 3 +++ src/PowerMeterMqtt.cpp | 8 -------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/PowerMeterMqtt.h b/include/PowerMeterMqtt.h index e63309f67..b12e919bc 100644 --- a/include/PowerMeterMqtt.h +++ b/include/PowerMeterMqtt.h @@ -18,7 +18,6 @@ class PowerMeterMqtt : public PowerMeterProvider { bool init() final; void loop() final { } float getPowerTotal() const final; - void doMqttPublish() const final; private: using MsgProperties = espMqttClientTypes::MessageProperties; @@ -26,6 +25,9 @@ class PowerMeterMqtt : public PowerMeterProvider { uint8_t const* payload, size_t len, size_t index, size_t total, float* targetVariable, PowerMeterMqttValue const* cfg); + // we don't need to republish data received from MQTT + void doMqttPublish() const final { }; + PowerMeterMqttConfig const _cfg; using power_values_t = std::array; diff --git a/src/PowerMeter.cpp b/src/PowerMeter.cpp index 3787dfe75..b6041e34e 100644 --- a/src/PowerMeter.cpp +++ b/src/PowerMeter.cpp @@ -87,5 +87,8 @@ void PowerMeterClass::loop() std::lock_guard lock(_mutex); if (!_upProvider) { return; } _upProvider->loop(); + + auto const& pmcfg = Configuration.get().PowerMeter; + if (pmcfg.Source == static_cast(PowerMeterProvider::Type::MQTT)) { return; } _upProvider->mqttLoop(); } diff --git a/src/PowerMeterMqtt.cpp b/src/PowerMeterMqtt.cpp index 787973702..99a51a69e 100644 --- a/src/PowerMeterMqtt.cpp +++ b/src/PowerMeterMqtt.cpp @@ -80,11 +80,3 @@ float PowerMeterMqtt::getPowerTotal() const for (auto v: _powerValues) { sum += v; } return sum; } - -void PowerMeterMqtt::doMqttPublish() const -{ - std::lock_guard l(_mutex); - mqttPublish("power1", _powerValues[0]); - mqttPublish("power2", _powerValues[1]); - mqttPublish("power3", _powerValues[2]); -}