Skip to content

Commit

Permalink
add: get "State of Operation", "Float voltage" and "Absorption Voltag…
Browse files Browse the repository at this point in the history
…e" from the Solar Charger
  • Loading branch information
SW-Niko committed Jan 23, 2025
1 parent 587f8ca commit 8a2aea4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/solarcharger/DummyStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class DummyStats : public Stats {
std::optional<uint16_t> getPanelPowerWatts() const final { return std::nullopt; }
std::optional<float> getYieldTotal() const final { return std::nullopt; }
std::optional<float> getYieldDay() const final { return std::nullopt; }
std::optional<uint8_t> getStateOfOperation() const final { return std::nullopt; }
std::optional<float> getFloatVoltage() const final { return std::nullopt; }
std::optional<float> getAbsorptionVoltage() const final { return std::nullopt; }
void getLiveViewData(JsonVariant& root, const boolean fullUpdate, const uint32_t lastPublish) const final {}
void mqttPublish() const final {}
void mqttPublishSensors(const boolean forcePublish) const final {}
Expand Down
9 changes: 9 additions & 0 deletions include/solarcharger/Stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ class Stats {
// sum of today's yield of all MPPT charge controllers in Wh
virtual std::optional<float> getYieldDay() const;

// state of operation from the first available controller
virtual std::optional<uint8_t> getStateOfOperation() const { return std::nullopt; };

// float voltage from the first available charge controller
virtual std::optional<float> getFloatVoltage() const { return std::nullopt; };

// absorption voltage from the first available charge controller
virtual std::optional<float> getAbsorptionVoltage() const { return std::nullopt; };

// convert stats to JSON for web application live view
virtual void getLiveViewData(JsonVariant& root, const boolean fullUpdate, const uint32_t lastPublish) const;

Expand Down
3 changes: 3 additions & 0 deletions include/solarcharger/victron/Stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Stats : public ::SolarChargers::Stats {
std::optional<uint16_t> getPanelPowerWatts() const final;
std::optional<float> getYieldTotal() const final;
std::optional<float> getYieldDay() const final;
std::optional<uint8_t> getStateOfOperation() const final;
std::optional<float> getFloatVoltage() const final;
std::optional<float> getAbsorptionVoltage() const final;

void getLiveViewData(JsonVariant& root, const boolean fullUpdate, const uint32_t lastPublish) const final;
void mqttPublish() const final;
Expand Down
33 changes: 33 additions & 0 deletions src/solarcharger/victron/Stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,39 @@ std::optional<float> Stats::getYieldDay() const
return sum;
}

std::optional<uint8_t> Stats::getStateOfOperation() const
{
for (auto const& entry : _data) {
if (!entry.second) { continue; }
return entry.second->currentState_CS;
}
return std::nullopt;
}

std::optional<float> Stats::getFloatVoltage() const
{
for (auto const& entry : _data) {
if (!entry.second) { continue; }
auto voltage = entry.second->BatteryFloatMilliVolt;
if (voltage.first > 0) { // only return valid and not outdated value
return voltage.second / 1000.0;
}
}
return std::nullopt;
}

std::optional<float> Stats::getAbsorptionVoltage() const
{
for (auto const& entry : _data) {
if (!entry.second) { continue; }
auto voltage = entry.second->BatteryAbsorptionMilliVolt;
if (voltage.first > 0) { // only return valid and not outdated value
return voltage.second / 1000.0;
}
}
return std::nullopt;
}

void Stats::getLiveViewData(JsonVariant& root, const boolean fullUpdate, const uint32_t lastPublish) const
{
::SolarChargers::Stats::getLiveViewData(root, fullUpdate, lastPublish);
Expand Down

0 comments on commit 8a2aea4

Please sign in to comment.