Skip to content

Commit

Permalink
live data: exclude data if respective feature disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
schlimmchen committed Mar 14, 2024
1 parent cf27bd2 commit 8895791
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/WebApi_ws_live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,55 @@ void WebApiWsLiveClass::wsCleanupTaskCb()

void WebApiWsLiveClass::generateOnBatteryJsonResponse(JsonVariant& root, bool all)
{
auto const& config = Configuration.get();
auto constexpr halfOfAllMillis = std::numeric_limits<uint32_t>::max() / 2;

if (all || (millis() - _lastPublishVictron) > VictronMppt.getDataAgeMillis()) {
auto victronAge = VictronMppt.getDataAgeMillis();
if (all || (victronAge > 0 && (millis() - _lastPublishVictron) > victronAge)) {
JsonObject vedirectObj = root.createNestedObject("vedirect");
vedirectObj["enabled"] = Configuration.get().Vedirect.Enabled;
JsonObject totalVeObj = vedirectObj.createNestedObject("total");
vedirectObj["enabled"] = config.Vedirect.Enabled;

addTotalField(totalVeObj, "Power", VictronMppt.getPanelPowerWatts(), "W", 1);
addTotalField(totalVeObj, "YieldDay", VictronMppt.getYieldDay() * 1000, "Wh", 0);
addTotalField(totalVeObj, "YieldTotal", VictronMppt.getYieldTotal(), "kWh", 2);
if (config.Vedirect.Enabled) {
JsonObject totalVeObj = vedirectObj.createNestedObject("total");
addTotalField(totalVeObj, "Power", VictronMppt.getPanelPowerWatts(), "W", 1);
addTotalField(totalVeObj, "YieldDay", VictronMppt.getYieldDay() * 1000, "Wh", 0);
addTotalField(totalVeObj, "YieldTotal", VictronMppt.getYieldTotal(), "kWh", 2);
}

if (!all) { _lastPublishVictron = millis(); }
}

if (all || (HuaweiCan.getLastUpdate() - _lastPublishHuawei) < halfOfAllMillis ) {
JsonObject huaweiObj = root.createNestedObject("huawei");
huaweiObj["enabled"] = Configuration.get().Huawei.Enabled;
const RectifierParameters_t * rp = HuaweiCan.get();
addTotalField(huaweiObj, "Power", rp->output_power, "W", 2);
huaweiObj["enabled"] = config.Huawei.Enabled;

if (config.Huawei.Enabled) {
const RectifierParameters_t * rp = HuaweiCan.get();
addTotalField(huaweiObj, "Power", rp->output_power, "W", 2);
}

if (!all) { _lastPublishHuawei = millis(); }
}

auto spStats = Battery.getStats();
if (all || spStats->updateAvailable(_lastPublishBattery)) {
JsonObject batteryObj = root.createNestedObject("battery");
batteryObj["enabled"] = Configuration.get().Battery.Enabled;
addTotalField(batteryObj, "soc", spStats->getSoC(), "%", 0);
batteryObj["enabled"] = config.Battery.Enabled;

if (config.Battery.Enabled) {
addTotalField(batteryObj, "soc", spStats->getSoC(), "%", 0);
}

if (!all) { _lastPublishBattery = millis(); }
}

if (all || (PowerMeter.getLastPowerMeterUpdate() - _lastPublishPowerMeter) < halfOfAllMillis) {
JsonObject powerMeterObj = root.createNestedObject("power_meter");
powerMeterObj["enabled"] = Configuration.get().PowerMeter.Enabled;
addTotalField(powerMeterObj, "Power", PowerMeter.getPowerTotal(false), "W", 1);
powerMeterObj["enabled"] = config.PowerMeter.Enabled;

if (config.PowerMeter.Enabled) {
addTotalField(powerMeterObj, "Power", PowerMeter.getPowerTotal(false), "W", 1);
}

if (!all) { _lastPublishPowerMeter = millis(); }
}
Expand Down

0 comments on commit 8895791

Please sign in to comment.