Skip to content

Commit

Permalink
Feature: Re-Request DevInfo if it contains invalid data
Browse files Browse the repository at this point in the history
It can sometimes occour that the DevInfo request returns invalid data. Currently this is identified if the firmware build year is < 2016. In this case the package will be re-requested now.
  • Loading branch information
tbnobody committed Aug 25, 2023
1 parent 08ca221 commit b88030f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/Hoymiles/src/Hoymiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,21 @@ void HoymilesClass::loop()
}

// Fetch dev info (but first fetch stats)
if (iv->Statistics()->getLastUpdate() > 0 && (iv->DevInfo()->getLastUpdateAll() == 0 || iv->DevInfo()->getLastUpdateSimple() == 0)) {
_messageOutput->println("Request device info");
iv->sendDevInfoRequest();
if (iv->Statistics()->getLastUpdate() > 0) {
bool invalidDevInfo = !iv->DevInfo()->containsValidData()
&& iv->DevInfo()->getLastUpdateAll() > 0
&& iv->DevInfo()->getLastUpdateSimple() > 0;

if (invalidDevInfo) {
_messageOutput->println("DevInfo: No Valid Data");
}

if ((iv->DevInfo()->getLastUpdateAll() == 0)
|| (iv->DevInfo()->getLastUpdateSimple() == 0)
|| invalidDevInfo) {
_messageOutput->println("Request device info");
iv->sendDevInfoRequest();
}
}

if (++inverterPos >= getNumInverters()) {
Expand Down
10 changes: 10 additions & 0 deletions lib/Hoymiles/src/parser/DevInfoParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ String DevInfoParser::getHwModelName()
return devInfo[idx].modelName;
}

bool DevInfoParser::containsValidData()
{
time_t t = getFwBuildDateTime();

struct tm info;
localtime_r(&t, &info);

return info.tm_year > (2016 - 1900);
}

uint8_t DevInfoParser::getDevIdx()
{
uint8_t ret = 0xff;
Expand Down
2 changes: 2 additions & 0 deletions lib/Hoymiles/src/parser/DevInfoParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class DevInfoParser : public Parser {
uint16_t getMaxPower();
String getHwModelName();

bool containsValidData();

private:
time_t timegm(struct tm* tm);
uint8_t getDevIdx();
Expand Down

0 comments on commit b88030f

Please sign in to comment.