Skip to content

Commit

Permalink
Fix: don't republish MQTT powermeter data to MQTT (#1250)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBoehm authored Sep 13, 2024
1 parent 86cab0f commit c96762c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 3 additions & 1 deletion include/PowerMeterMqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ class PowerMeterMqtt : public PowerMeterProvider {
bool init() final;
void loop() final { }
float getPowerTotal() const final;
void doMqttPublish() const final;

private:
using MsgProperties = espMqttClientTypes::MessageProperties;
void onMessage(MsgProperties const& properties, char const* topic,
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<float, POWERMETER_MQTT_MAX_VALUES>;
Expand Down
3 changes: 3 additions & 0 deletions src/PowerMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,8 @@ void PowerMeterClass::loop()
std::lock_guard<std::mutex> lock(_mutex);
if (!_upProvider) { return; }
_upProvider->loop();

auto const& pmcfg = Configuration.get().PowerMeter;
if (pmcfg.Source == static_cast<uint8_t>(PowerMeterProvider::Type::MQTT)) { return; }
_upProvider->mqttLoop();
}
8 changes: 0 additions & 8 deletions src/PowerMeterMqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,3 @@ float PowerMeterMqtt::getPowerTotal() const
for (auto v: _powerValues) { sum += v; }
return sum;
}

void PowerMeterMqtt::doMqttPublish() const
{
std::lock_guard<std::mutex> l(_mutex);
mqttPublish("power1", _powerValues[0]);
mqttPublish("power2", _powerValues[1]);
mqttPublish("power3", _powerValues[2]);
}

0 comments on commit c96762c

Please sign in to comment.