Skip to content

Commit

Permalink
Reworked get_payload()
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-bs authored Apr 18, 2023
1 parent 461753f commit 18c0e27
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions src/payload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,39 +152,45 @@ void get_payload(uint8_t port, LoraEncoder & encoder)
do {
result = growattInterface.ReadInputRegisters(NULL);
log_d("ReadInputRegisters: 0x%02x", result);
if ((result != growattInterface.Continue) && (result != growattInterface.Success)) {
String message = growattInterface.sendModbusError(result);
log_e("Error: %s", message.c_str());
}
while (result == growattInterface.Continue) {
delay(1000);
result = growattInterface.ReadInputRegisters(NULL);
log_d("ReadInputRegisters: 0x%02x", result);
}

encoder.writeUint8(result);
if (result == growattInterface.Success) {
if (port == 1) {
encoder.writeUint8(growattInterface.modbusdata.status);
encoder.writeUint8(growattInterface.modbusdata.faultcode);
encoder.writeRawFloat(growattInterface.modbusdata.pv1voltage);
encoder.writeRawFloat(growattInterface.modbusdata.pv1current);
encoder.writeRawFloat(growattInterface.modbusdata.pv1power);
encoder.writeRawFloat(growattInterface.modbusdata.outputpower);
encoder.writeRawFloat(growattInterface.modbusdata.gridvoltage);
encoder.writeRawFloat(growattInterface.modbusdata.gridfrequency);

String message = growattInterface.sendModbusError(result);
if (result != growattInterface.Continue && (result != growattInterface.Success)) {
log_e("Error: %s", message.c_str());
delay(1000);
} else {
encoder.writeRawFloat(growattInterface.modbusdata.energytoday);
encoder.writeRawFloat(growattInterface.modbusdata.energytotal);
encoder.writeRawFloat(growattInterface.modbusdata.totalworktime);
encoder.writeTemperature(growattInterface.modbusdata.tempinverter);
encoder.writeTemperature(growattInterface.modbusdata.tempipm);
encoder.writeRawFloat(growattInterface.modbusdata.pv1energytoday);
encoder.writeRawFloat(growattInterface.modbusdata.pv1energytotal);

log_d("%s", message.c_str());
}

} else if (result != growattInterface.Continue) {
String message = growattInterface.sendModbusError(result);
log_e("Error: %s", message.c_str());
delay(1000);
}
} while ((result != growattInterface.Success) && (++retries < MODBUS_RETRIES));

encoder.writeUint8(result);
if (result == growattInterface.Success) {
log_v("Port: %d", port);
if (port == 1) {
encoder.writeUint8(growattInterface.modbusdata.status);
encoder.writeUint8(growattInterface.modbusdata.faultcode);
encoder.writeRawFloat(growattInterface.modbusdata.pv1voltage);
encoder.writeRawFloat(growattInterface.modbusdata.pv1current);
encoder.writeRawFloat(growattInterface.modbusdata.pv1power);
encoder.writeRawFloat(growattInterface.modbusdata.outputpower);
encoder.writeRawFloat(growattInterface.modbusdata.gridvoltage);
encoder.writeRawFloat(growattInterface.modbusdata.gridfrequency);

} else {
encoder.writeRawFloat(growattInterface.modbusdata.energytoday);
encoder.writeRawFloat(growattInterface.modbusdata.energytotal);
encoder.writeRawFloat(growattInterface.modbusdata.totalworktime);
encoder.writeTemperature(growattInterface.modbusdata.tempinverter);
encoder.writeTemperature(growattInterface.modbusdata.tempipm);
encoder.writeRawFloat(growattInterface.modbusdata.pv1energytoday);
encoder.writeRawFloat(growattInterface.modbusdata.pv1energytotal);

}
}
}

0 comments on commit 18c0e27

Please sign in to comment.