Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/VictronMppt.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ class VictronMpptClass {
// total output of all MPPT charge controllers in Watts
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:
VictronMpptClass(VictronMpptClass const& other) = delete;
VictronMpptClass(VictronMpptClass&& other) = delete;
Expand Down
35 changes: 34 additions & 1 deletion src/VictronMppt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ VeDirectMpptController::spData_t VictronMpptClass::getData(size_t idx) const
if (_controllers.empty() || idx >= _controllers.size()) {
MessageOutput.printf("ERROR: MPPT controller index %d is out of bounds (%d controllers)\r\n",
idx, _controllers.size());
return VeDirectMpptController::spData_t{};
return std::make_shared<VeDirectMpptController::veMpptStruct>();
}

return _controllers[idx]->getData();
Expand All @@ -94,3 +94,36 @@ int32_t VictronMpptClass::getPowerOutputWatts() const

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;
}
7 changes: 3 additions & 4 deletions src/WebApi_ws_live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,9 @@ void WebApiWsLiveClass::generateJsonResponse(JsonVariant& root)
vedirectObj[F("enabled")] = Configuration.get().Vedirect_Enabled;
JsonObject totalVeObj = vedirectObj.createNestedObject("total");

auto spMpptData = VictronMppt.getData();
addTotalField(totalVeObj, "Power", spMpptData->PPV, "W", 1);
addTotalField(totalVeObj, "YieldDay", spMpptData->H20 * 1000, "Wh", 0);
addTotalField(totalVeObj, "YieldTotal", spMpptData->H19, "kWh", 2);
addTotalField(totalVeObj, "Power", VictronMppt.getPanelPowerWatts(), "W", 1);
addTotalField(totalVeObj, "YieldDay", VictronMppt.getYieldDay() * 1000, "Wh", 0);
addTotalField(totalVeObj, "YieldTotal", VictronMppt.getYieldTotal(), "kWh", 2);

JsonObject huaweiObj = root.createNestedObject("huawei");
huaweiObj[F("enabled")] = Configuration.get().Huawei_Enabled;
Expand Down