diff --git a/GoodWeCommunicator.cpp b/GoodWeCommunicator.cpp index ef6e765..b6b0388 100644 --- a/GoodWeCommunicator.cpp +++ b/GoodWeCommunicator.cpp @@ -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 @@ -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() diff --git a/PVOutputPublisher.cpp b/PVOutputPublisher.cpp index c93ad0e..ca5f38e 100644 --- a/PVOutputPublisher.cpp +++ b/PVOutputPublisher.cpp @@ -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 @@ -178,4 +180,7 @@ void PVOutputPublisher::ResetAverage() currentPacSum = 0; currentVoltageSum = 0; currentTempSum = 0; + lastPac = 0; + lastVoltage = 0; + lastTemp = 0; }