live data: exclude data if respective feature disabled
This commit is contained in:
parent
cf27bd29d7
commit
8895791145
@ -56,25 +56,32 @@ void WebApiWsLiveClass::wsCleanupTaskCb()
|
|||||||
|
|
||||||
void WebApiWsLiveClass::generateOnBatteryJsonResponse(JsonVariant& root, bool all)
|
void WebApiWsLiveClass::generateOnBatteryJsonResponse(JsonVariant& root, bool all)
|
||||||
{
|
{
|
||||||
|
auto const& config = Configuration.get();
|
||||||
auto constexpr halfOfAllMillis = std::numeric_limits<uint32_t>::max() / 2;
|
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");
|
JsonObject vedirectObj = root.createNestedObject("vedirect");
|
||||||
vedirectObj["enabled"] = Configuration.get().Vedirect.Enabled;
|
vedirectObj["enabled"] = config.Vedirect.Enabled;
|
||||||
JsonObject totalVeObj = vedirectObj.createNestedObject("total");
|
|
||||||
|
|
||||||
|
if (config.Vedirect.Enabled) {
|
||||||
|
JsonObject totalVeObj = vedirectObj.createNestedObject("total");
|
||||||
addTotalField(totalVeObj, "Power", VictronMppt.getPanelPowerWatts(), "W", 1);
|
addTotalField(totalVeObj, "Power", VictronMppt.getPanelPowerWatts(), "W", 1);
|
||||||
addTotalField(totalVeObj, "YieldDay", VictronMppt.getYieldDay() * 1000, "Wh", 0);
|
addTotalField(totalVeObj, "YieldDay", VictronMppt.getYieldDay() * 1000, "Wh", 0);
|
||||||
addTotalField(totalVeObj, "YieldTotal", VictronMppt.getYieldTotal(), "kWh", 2);
|
addTotalField(totalVeObj, "YieldTotal", VictronMppt.getYieldTotal(), "kWh", 2);
|
||||||
|
}
|
||||||
|
|
||||||
if (!all) { _lastPublishVictron = millis(); }
|
if (!all) { _lastPublishVictron = millis(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (all || (HuaweiCan.getLastUpdate() - _lastPublishHuawei) < halfOfAllMillis ) {
|
if (all || (HuaweiCan.getLastUpdate() - _lastPublishHuawei) < halfOfAllMillis ) {
|
||||||
JsonObject huaweiObj = root.createNestedObject("huawei");
|
JsonObject huaweiObj = root.createNestedObject("huawei");
|
||||||
huaweiObj["enabled"] = Configuration.get().Huawei.Enabled;
|
huaweiObj["enabled"] = config.Huawei.Enabled;
|
||||||
|
|
||||||
|
if (config.Huawei.Enabled) {
|
||||||
const RectifierParameters_t * rp = HuaweiCan.get();
|
const RectifierParameters_t * rp = HuaweiCan.get();
|
||||||
addTotalField(huaweiObj, "Power", rp->output_power, "W", 2);
|
addTotalField(huaweiObj, "Power", rp->output_power, "W", 2);
|
||||||
|
}
|
||||||
|
|
||||||
if (!all) { _lastPublishHuawei = millis(); }
|
if (!all) { _lastPublishHuawei = millis(); }
|
||||||
}
|
}
|
||||||
@ -82,16 +89,22 @@ void WebApiWsLiveClass::generateOnBatteryJsonResponse(JsonVariant& root, bool al
|
|||||||
auto spStats = Battery.getStats();
|
auto spStats = Battery.getStats();
|
||||||
if (all || spStats->updateAvailable(_lastPublishBattery)) {
|
if (all || spStats->updateAvailable(_lastPublishBattery)) {
|
||||||
JsonObject batteryObj = root.createNestedObject("battery");
|
JsonObject batteryObj = root.createNestedObject("battery");
|
||||||
batteryObj["enabled"] = Configuration.get().Battery.Enabled;
|
batteryObj["enabled"] = config.Battery.Enabled;
|
||||||
|
|
||||||
|
if (config.Battery.Enabled) {
|
||||||
addTotalField(batteryObj, "soc", spStats->getSoC(), "%", 0);
|
addTotalField(batteryObj, "soc", spStats->getSoC(), "%", 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (!all) { _lastPublishBattery = millis(); }
|
if (!all) { _lastPublishBattery = millis(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (all || (PowerMeter.getLastPowerMeterUpdate() - _lastPublishPowerMeter) < halfOfAllMillis) {
|
if (all || (PowerMeter.getLastPowerMeterUpdate() - _lastPublishPowerMeter) < halfOfAllMillis) {
|
||||||
JsonObject powerMeterObj = root.createNestedObject("power_meter");
|
JsonObject powerMeterObj = root.createNestedObject("power_meter");
|
||||||
powerMeterObj["enabled"] = Configuration.get().PowerMeter.Enabled;
|
powerMeterObj["enabled"] = config.PowerMeter.Enabled;
|
||||||
|
|
||||||
|
if (config.PowerMeter.Enabled) {
|
||||||
addTotalField(powerMeterObj, "Power", PowerMeter.getPowerTotal(false), "W", 1);
|
addTotalField(powerMeterObj, "Power", PowerMeter.getPowerTotal(false), "W", 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (!all) { _lastPublishPowerMeter = millis(); }
|
if (!all) { _lastPublishPowerMeter = millis(); }
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user