Skip to content

Commit

Permalink
Inverter isOnline detection fixed. Extra logging added
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan ten Hove committed Jun 16, 2017
1 parent f294dce commit 7149b76
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions GoodWeCommunicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ int GoodWeCommunicator::sendData(char address, char controlCode, char functionCo
goodweSerial->write(low);
if (debugMode)
{
Serial.print("CRC high/low: ");
debugPrintHex(high);
debugPrintHex(low);
Serial.println(".");
Expand All @@ -92,7 +93,8 @@ void GoodWeCommunicator::debugPrintHex(char bt)
void GoodWeCommunicator::sendDiscovery()
{
//send out discovery for unregistered devices.
Serial.println("Sending discovery");
if(debugMode)
Serial.println("Sending discovery");
sendData(0x7F, 0x00, 0x00, 0x00, nullptr);
}

Expand All @@ -103,10 +105,22 @@ void GoodWeCommunicator::checkOfflineInverters()
{
if (inverters[index].isOnline)
{
inverters[index].isOnline = (millis() - inverters[index].lastSeen < OFFLINE_TIMEOUT);
auto newOnline = (millis() - inverters[index].lastSeen < OFFLINE_TIMEOUT);

//check if inverter timed out
if(!inverters[index].isOnline)
if (!newOnline && inverters[index].isOnline)
{
if (debugMode)
{
Serial.print("Marking inverter @ address: ");
Serial.print((short)inverters[index].address);
Serial.println("offline.");
}

sendRemoveRegistration(inverters[index].address); //send in case the inverter thinks we are online
}
inverters[index].isOnline = newOnline;

}

}
Expand Down Expand Up @@ -235,6 +249,8 @@ void GoodWeCommunicator::handleRegistration(char * serialNumber, char length)
//check inverter
if (memcmp(inverters[index].serialNumber, serialNumber, 16) == 0)
{
Serial.print("Already registered inverter reregistered with address: ");
Serial.println((short)inverters[index].address);
//found it. Set to unconfirmed and send out the existing address to the inverter
inverters[index].addressConfirmed = false;
inverters[index].lastSeen = millis();
Expand Down Expand Up @@ -272,6 +288,7 @@ void GoodWeCommunicator::handleRegistrationConfirmation(char address)
if (inverter)
{
inverter->addressConfirmed = true;
inverter->isOnline = true;
inverter->lastSeen = millis();
}
//get the information straight away
Expand Down

0 comments on commit 7149b76

Please sign in to comment.