Fix: VE.Direct refactor issues from #505 (#516)

* VE.Direct: return non-nullptr as a fallback

the changed return statement was supposed to return a shared_ptr to a
new and valid MPPT data struct as a fallback. however, it did return a
new shared_ptr that was initialized to nullptr.

* VE.Direct: make liveview total use total MPPT values

this change makes the call to VictronMppt.getData() obsolete, which in
turn will therefore not cause an error message on the console if
VE.Direct (MPPT) is not enabled. this change also takes care that once
multiple VE.Direct MPPT charge controllers are supported, the sums of
the respective total values are used in the web app totals.
This commit is contained in:
Bernhard Kirchen 2023-10-23 13:23:06 +02:00 committed by GitHub
parent 8ba9048f99
commit 0fa2745ace
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 5 deletions

View File

@ -25,6 +25,15 @@ public:
// total output of all MPPT charge controllers in Watts // total output of all MPPT charge controllers in Watts
int32_t getPowerOutputWatts() const; int32_t getPowerOutputWatts() const;
// total panel input power of all MPPT charge controllers in Watts
int32_t getPanelPowerWatts() const;
// sum of total yield of all MPPT charge controllers in kWh
double getYieldTotal() const;
// sum of today's yield of all MPPT charge controllers in kWh
double getYieldDay() const;
private: private:
VictronMpptClass(VictronMpptClass const& other) = delete; VictronMpptClass(VictronMpptClass const& other) = delete;
VictronMpptClass(VictronMpptClass&& other) = delete; VictronMpptClass(VictronMpptClass&& other) = delete;

View File

@ -78,7 +78,7 @@ VeDirectMpptController::spData_t VictronMpptClass::getData(size_t idx) const
if (_controllers.empty() || idx >= _controllers.size()) { if (_controllers.empty() || idx >= _controllers.size()) {
MessageOutput.printf("ERROR: MPPT controller index %d is out of bounds (%d controllers)\r\n", MessageOutput.printf("ERROR: MPPT controller index %d is out of bounds (%d controllers)\r\n",
idx, _controllers.size()); idx, _controllers.size());
return VeDirectMpptController::spData_t{}; return std::make_shared<VeDirectMpptController::veMpptStruct>();
} }
return _controllers[idx]->getData(); return _controllers[idx]->getData();
@ -94,3 +94,36 @@ int32_t VictronMpptClass::getPowerOutputWatts() const
return sum; return sum;
} }
int32_t VictronMpptClass::getPanelPowerWatts() const
{
int32_t sum = 0;
for (const auto& upController : _controllers) {
sum += upController->getData()->PPV;
}
return sum;
}
double VictronMpptClass::getYieldTotal() const
{
double sum = 0;
for (const auto& upController : _controllers) {
sum += upController->getData()->H19;
}
return sum;
}
double VictronMpptClass::getYieldDay() const
{
double sum = 0;
for (const auto& upController : _controllers) {
sum += upController->getData()->H20;
}
return sum;
}

View File

@ -192,10 +192,9 @@ void WebApiWsLiveClass::generateJsonResponse(JsonVariant& root)
vedirectObj[F("enabled")] = Configuration.get().Vedirect_Enabled; vedirectObj[F("enabled")] = Configuration.get().Vedirect_Enabled;
JsonObject totalVeObj = vedirectObj.createNestedObject("total"); JsonObject totalVeObj = vedirectObj.createNestedObject("total");
auto spMpptData = VictronMppt.getData(); addTotalField(totalVeObj, "Power", VictronMppt.getPanelPowerWatts(), "W", 1);
addTotalField(totalVeObj, "Power", spMpptData->PPV, "W", 1); addTotalField(totalVeObj, "YieldDay", VictronMppt.getYieldDay() * 1000, "Wh", 0);
addTotalField(totalVeObj, "YieldDay", spMpptData->H20 * 1000, "Wh", 0); addTotalField(totalVeObj, "YieldTotal", VictronMppt.getYieldTotal(), "kWh", 2);
addTotalField(totalVeObj, "YieldTotal", spMpptData->H19, "kWh", 2);
JsonObject huaweiObj = root.createNestedObject("huawei"); JsonObject huaweiObj = root.createNestedObject("huawei");
huaweiObj[F("enabled")] = Configuration.get().Huawei_Enabled; huaweiObj[F("enabled")] = Configuration.get().Huawei_Enabled;