Skip to content

Commit

Permalink
perf(PowerMeter): query PowerMeter on demand
Browse files Browse the repository at this point in the history
In addition to the cyclic query of the power meters, they will be queried on demand when total power is requested and last update is older than 1 second.
  • Loading branch information
helgeerbe committed Jun 14, 2023
1 parent 8dac88e commit 86ee7e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions include/PowerMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class PowerMeterClass {

bool mqttInitDone = false;

void readPowerMeter();

bool smlReadLoop();
const std::list<OBISHandler> smlHandlerList{
{{0x01, 0x00, 0x10, 0x07, 0x00, 0xff}, &smlOBISW, &_powerMeter1Power},
Expand Down
24 changes: 18 additions & 6 deletions src/PowerMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ void PowerMeterClass::onMqttMessage(const espMqttClientTypes::MessageProperties&

float PowerMeterClass::getPowerTotal()
{
CONFIG_T& config = Configuration.get();
if (!config.PowerMeter_Enabled
|| (millis() - _lastPowerMeterUpdate) < (1000)) {
readPowerMeter();
}
return _powerMeter1Power + _powerMeter2Power + _powerMeter3Power;
}

Expand Down Expand Up @@ -137,6 +142,19 @@ void PowerMeterClass::loop()
return;
}

readPowerMeter();

MessageOutput.printf("PowerMeterClass: TotalPower: %5.2f\r\n", getPowerTotal());

mqtt();

_lastPowerMeterCheck = millis();
}

void PowerMeterClass::readPowerMeter()
{
CONFIG_T& config = Configuration.get();

uint8_t _address = config.PowerMeter_SdmAddress;

if (config.PowerMeter_Source == SOURCE_SDM1PH) {
Expand Down Expand Up @@ -169,12 +187,6 @@ void PowerMeterClass::loop()
_lastPowerMeterUpdate = millis();
}
}

MessageOutput.printf("PowerMeterClass: TotalPower: %5.2f\r\n", getPowerTotal());

mqtt();

_lastPowerMeterCheck = millis();
}

bool PowerMeterClass::smlReadLoop()
Expand Down

0 comments on commit 86ee7e1

Please sign in to comment.