Skip to content

Commit

Permalink
Possible fix + extra logging for false pvoutput startup value
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan ten Hove committed Jun 28, 2017
1 parent b706ad8 commit dd9af05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 6 additions & 4 deletions GoodWeCommunicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void GoodWeCommunicator::handleRegistrationConfirmation(char address)
if (debugMode)
Serial.println("Inverter information found in list of inverters.");
inverter->addressConfirmed = true;
inverter->isOnline = true;
inverter->isOnline = false; //inverter is online, but we first need to get its information
inverter->lastSeen = millis();
}
else
Expand Down Expand Up @@ -337,17 +337,19 @@ void GoodWeCommunicator::handleIncomingInformation(char address, char dataLength
inverter->fac2 = bytesToFloat(data + dtPtr, 100); dtPtr += 2;
inverter->fac3 = bytesToFloat(data + dtPtr, 100); dtPtr += 2;
}
inverter->pac = ((short)(data[dtPtr]) << 8) | (data[dtPtr +1]); dtPtr += 2;
inverter->workMode = ((short)(data[dtPtr]) << 8) | (data[dtPtr + 1]); dtPtr += 2;
inverter->pac = ((unsigned short)(data[dtPtr]) << 8) | (data[dtPtr +1]); dtPtr += 2;
inverter->workMode = ((unsigned short)(data[dtPtr]) << 8) | (data[dtPtr + 1]); dtPtr += 2;
//TODO: Get the other values too
inverter->temp = bytesToFloat(data + dtPtr, 10); dtPtr += inverter->isDTSeries ? 34 : 26;
inverter->eDay = bytesToFloat(data + dtPtr, 10);
//isonline is set after first batch of data is set so readers get actual data
inverter->isOnline = true;
}

float GoodWeCommunicator::bytesToFloat(char * bt, char factor)
{
//convert two byte to float by converting to short and then dividing it by factor
return float(((short)bt[0] << 8) | bt[1]) / factor;
return float(((unsigned short)bt[0] << 8) | bt[1]) / factor;
}

void GoodWeCommunicator::askAllInvertersForInformation()
Expand Down
7 changes: 6 additions & 1 deletion PVOutputPublisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ void PVOutputPublisher::sendToPvOutput(GoodWeCommunicator::GoodweInverterInforma
if (debugMode)
{
Serial.print("Got some readings to calculate the avg power, temp and voltage. # readings: ");
Serial.println(avgCounter);
Serial.print(avgCounter);
Serial.print(", pac sum: ");
Serial.println(currentPacSum);
}

postMsg += String("&v2=") + String(currentPacSum / avgCounter); //improve resolution by adding avg power to prev val
Expand Down Expand Up @@ -178,4 +180,7 @@ void PVOutputPublisher::ResetAverage()
currentPacSum = 0;
currentVoltageSum = 0;
currentTempSum = 0;
lastPac = 0;
lastVoltage = 0;
lastTemp = 0;
}

0 comments on commit dd9af05

Please sign in to comment.