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

Minor corrections: Solar charger - Victron #1623

Merged
merged 3 commits into from
Feb 14, 2025
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
4 changes: 2 additions & 2 deletions include/solarcharger/Stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class Stats {
enum class StateOfOperation : uint8_t { Off = 0, Bulk = 1, Absorption = 2, Float = 3, Various = 255 };
virtual std::optional<Stats::StateOfOperation> getStateOfOperation() const;

// float voltage from the first available charge controller
// float voltage from the first available charge controller in V
virtual std::optional<float> getFloatVoltage() const;

// absorption voltage from the first available charge controller
// absorption voltage from the first available charge controller in V
virtual std::optional<float> getAbsorptionVoltage() const;

// convert stats to JSON for web application live view
Expand Down
36 changes: 13 additions & 23 deletions src/solarcharger/victron/Stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,83 +33,74 @@ uint32_t Stats::getAgeMillis() const

std::optional<float> Stats::getOutputPowerWatts() const
{
float sum = 0;
auto data = false;
std::optional<float> sum = std::nullopt;

for (auto const& entry : _data) {
if (!entry.second) { continue; }
data = true;
sum += entry.second->batteryOutputPower_W;

sum = sum.has_value() ? *sum + entry.second->batteryOutputPower_W : entry.second->batteryOutputPower_W;
}

if (!data) { return std::nullopt; }

return sum;
}

std::optional<float> Stats::getOutputVoltage() const
{
float min = -1;
std::optional<float> min = std::nullopt;

for (auto const& entry : _data) {
if (!entry.second) { continue; }

float volts = entry.second->batteryVoltage_V_mV / 1000.0;
if (min == -1) { min = volts; }
min = std::min(min, volts);
min = min.has_value() ? std::min(*min, volts) : volts;
}

if (min == -1) { return std::nullopt; }

return min;
}

std::optional<uint16_t> Stats::getPanelPowerWatts() const
{
uint16_t sum = 0;
auto data = false;
std::optional<float> sum = std::nullopt;

for (auto const& entry : _data) {
if (!entry.second) { continue; }
data = true;

// if any charge controller is part of a VE.Smart network, and if the
// charge controller is connected in a way that allows to send
// requests, we should have the "network total DC input power" available.
auto networkPower = entry.second->NetworkTotalDcInputPowerMilliWatts;
if (networkPower.first > 0) {
return static_cast<int32_t>(networkPower.second / 1000.0);
return static_cast<uint16_t>(networkPower.second / 1000.0);
AndreasBoehm marked this conversation as resolved.
Show resolved Hide resolved
}

sum += entry.second->panelPower_PPV_W;
sum = sum.has_value() ? *sum + entry.second->panelPower_PPV_W : entry.second->panelPower_PPV_W;
}

if (!data) { return std::nullopt; }

return sum;
}

std::optional<float> Stats::getYieldTotal() const
{
float sum = 0;
std::optional<float> sum = std::nullopt;

for (auto const& entry : _data) {
if (!entry.second) { continue; }

sum += entry.second->yieldTotal_H19_Wh / 1000.0;
float yield = entry.second->yieldTotal_H19_Wh / 1000.0;
sum = sum.has_value() ? *sum + yield : yield;
}

return sum;
}

std::optional<float> Stats::getYieldDay() const
{
float sum = 0;
std::optional<float> sum = std::nullopt;

for (auto const& entry : _data) {
if (!entry.second) { continue; }

sum += entry.second->yieldToday_H20_Wh;
sum = sum.has_value() ? *sum + entry.second->yieldToday_H20_Wh : entry.second->yieldToday_H20_Wh;
}

return sum;
Expand All @@ -123,7 +114,6 @@ std::optional<Stats::StateOfOperation> Stats::getStateOfOperation() const
switch (entry.second->currentState_CS) {
case 0: return Stats::StateOfOperation::Off;
case 3: return Stats::StateOfOperation::Bulk;
case 246:
case 4: return Stats::StateOfOperation::Absorption;
case 5: return Stats::StateOfOperation::Float;
default: return Stats::StateOfOperation::Various;
Expand Down