forked from tbnobody/OpenDTU
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement global data store to handle all invert total values
Use the new values in the LED, MQTT and Web interface.
- Loading branch information
Showing
6 changed files
with
188 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#pragma once | ||
|
||
#include <TimeoutHelper.h> | ||
|
||
class DatastoreClass { | ||
public: | ||
DatastoreClass(); | ||
void init(); | ||
void loop(); | ||
|
||
// Sum of yield total of all enabled inverters, a inverter which is just disabled at night is also included | ||
float totalAcYieldTotalEnabled = 0; | ||
|
||
// Sum of yield day of all enabled inverters, a inverter which is just disabled at night is also included | ||
float totalAcYieldDayEnabled = 0; | ||
|
||
// Sum of total AC power of all enabled inverters | ||
float totalAcPowerEnabled = 0; | ||
|
||
// Sum of total DC power of all enabled inverters | ||
float totalDcPowerEnabled = 0; | ||
|
||
// Sum of total DC power of all enabled inverters with maxStringPower set | ||
float totalDcPowerIrradiation = 0; | ||
|
||
// Sum of total installed irradiation of all enabled inverters | ||
float totalDcIrradiationInstalled = 0; | ||
|
||
// Percentage (1-100) of total irradiation | ||
float totalDcIrradiation = 0; | ||
|
||
// Amount of relevant digits for yield total | ||
unsigned int totalAcYieldTotalDigits = 0; | ||
|
||
// Amount of relevant digits for yield total | ||
unsigned int totalAcYieldDayDigits = 0; | ||
|
||
// Amount of relevant digits for AC power | ||
unsigned int totalAcPowerDigits = 0; | ||
|
||
// Amount of relevant digits for DC power | ||
unsigned int totalDcPowerDigits = 0; | ||
|
||
// True, if at least one inverter is reachable | ||
bool isAtLeastOneReachable = false; | ||
|
||
// True if at least one inverter is producing | ||
bool isAtLeastOneProducing = false; | ||
|
||
// True if all enabled inverters are producing | ||
bool isAllEnabledProducing = false; | ||
|
||
// True if all enabled inverters are reachable | ||
bool isAllEnabledReachable = false; | ||
|
||
private: | ||
TimeoutHelper _updateTimeout; | ||
}; | ||
|
||
extern DatastoreClass Datastore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Copyright (C) 2023 Thomas Basler and others | ||
*/ | ||
#include "Datastore.h" | ||
#include "Configuration.h" | ||
#include <Hoymiles.h> | ||
|
||
DatastoreClass Datastore; | ||
|
||
DatastoreClass::DatastoreClass() | ||
{ | ||
} | ||
|
||
void DatastoreClass::init() | ||
{ | ||
_updateTimeout.set(1000); | ||
} | ||
|
||
void DatastoreClass::loop() | ||
{ | ||
if (Hoymiles.isAllRadioIdle() && _updateTimeout.occured()) { | ||
|
||
uint8_t isProducing = 0; | ||
uint8_t isReachable = 0; | ||
|
||
totalAcYieldTotalEnabled = 0; | ||
totalAcYieldTotalDigits = 0; | ||
|
||
totalAcYieldDayEnabled = 0; | ||
totalAcYieldDayDigits = 0; | ||
|
||
totalAcPowerEnabled = 0; | ||
totalAcPowerDigits = 0; | ||
|
||
totalDcPowerEnabled = 0; | ||
totalDcPowerDigits = 0; | ||
|
||
totalDcPowerIrradiation = 0; | ||
totalDcIrradiationInstalled = 0; | ||
|
||
isAllEnabledProducing = true; | ||
isAllEnabledReachable = true; | ||
|
||
for (uint8_t i = 0; i < Hoymiles.getNumInverters(); i++) { | ||
auto inv = Hoymiles.getInverterByPos(i); | ||
if (inv == nullptr) { | ||
continue; | ||
} | ||
|
||
auto cfg = Configuration.getInverterConfig(inv->serial()); | ||
if (cfg == nullptr) { | ||
continue; | ||
} | ||
|
||
if (inv->isProducing()) { | ||
isProducing++; | ||
} else { | ||
if (inv->getEnablePolling()) { | ||
isAllEnabledProducing = false; | ||
} | ||
} | ||
|
||
if (inv->isReachable()) { | ||
isReachable++; | ||
} else { | ||
if (inv->getEnablePolling()) { | ||
isAllEnabledReachable = false; | ||
} | ||
} | ||
|
||
for (auto& c : inv->Statistics()->getChannelsByType(TYPE_AC)) { | ||
if (cfg->Poll_Enable) { | ||
totalAcYieldTotalEnabled += inv->Statistics()->getChannelFieldValue(TYPE_AC, c, FLD_YT); | ||
totalAcYieldDayEnabled += inv->Statistics()->getChannelFieldValue(TYPE_AC, c, FLD_YD); | ||
|
||
totalAcYieldTotalDigits = max<unsigned int>(totalAcYieldTotalDigits, inv->Statistics()->getChannelFieldDigits(TYPE_AC, c, FLD_YT)); | ||
totalAcYieldDayDigits = max<unsigned int>(totalAcYieldDayDigits, inv->Statistics()->getChannelFieldDigits(TYPE_AC, c, FLD_YD)); | ||
} | ||
if (inv->getEnablePolling()) { | ||
totalAcPowerEnabled += inv->Statistics()->getChannelFieldValue(TYPE_AC, c, FLD_PAC); | ||
totalAcPowerDigits = max<unsigned int>(totalAcPowerDigits, inv->Statistics()->getChannelFieldDigits(TYPE_AC, c, FLD_PAC)); | ||
} | ||
} | ||
|
||
for (auto& c : inv->Statistics()->getChannelsByType(TYPE_DC)) { | ||
if (inv->getEnablePolling()) { | ||
totalDcPowerEnabled += inv->Statistics()->getChannelFieldValue(TYPE_DC, c, FLD_PDC); | ||
totalDcPowerDigits = max<unsigned int>(totalDcPowerDigits, inv->Statistics()->getChannelFieldDigits(TYPE_DC, c, FLD_PDC)); | ||
|
||
if (inv->Statistics()->getStringMaxPower(c) > 0) { | ||
totalDcPowerIrradiation += inv->Statistics()->getChannelFieldValue(TYPE_DC, c, FLD_PDC); | ||
totalDcIrradiationInstalled += inv->Statistics()->getStringMaxPower(c); | ||
} | ||
} | ||
} | ||
} | ||
|
||
isAtLeastOneProducing = isProducing > 0; | ||
isAtLeastOneReachable = isReachable > 0; | ||
|
||
totalDcIrradiation = totalDcIrradiationInstalled > 0 ? totalDcPowerIrradiation / totalDcIrradiationInstalled * 100.0f : 0; | ||
|
||
_updateTimeout.reset(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters