Skip to content

Commit

Permalink
single phase inverters: use variable to fill them to phase 1 to smart…
Browse files Browse the repository at this point in the history
…meter
  • Loading branch information
Alois Klingler committed Aug 8, 2023
1 parent a4e8644 commit 6bc9acb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/ModbusDtu.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ModbusDtu.h"
#include "Datastore.h"
//#include "MessageOutput.h"

ModbusIP mb;

Expand Down Expand Up @@ -89,7 +90,9 @@ void ModbusDtuClass::init()

void ModbusDtuClass::loop()
{
if (millis() - _lastPublish > 5000 && Hoymiles.isAllRadioIdle()) {
const CONFIG_T& config = Configuration.get();
if (millis() - _lastPublish > (config.Dtu_PollInterval * 1000) && Hoymiles.isAllRadioIdle()) {
// MessageOutput.printf("Modbus start %lu\r\n", millis());
if (Hoymiles.getNumInverters() == 1) {
auto inv = Hoymiles.getInverterByPos(0);
if (inv != nullptr) {
Expand All @@ -100,7 +103,7 @@ void ModbusDtuClass::loop()
value = (inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_IAC));
mb.Hreg(0x9c87, hexbytes[1]);
mb.Hreg(0x9c88, hexbytes[0]);
value = (inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_IAC_1));
value = ((inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_IAC_1) != 0 ? inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_IAC_1) : inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_IAC)));
mb.Hreg(0x9c89, hexbytes[1]);
mb.Hreg(0x9c8a, hexbytes[0]);
value = (inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_IAC_2));
Expand All @@ -109,7 +112,7 @@ void ModbusDtuClass::loop()
value = (inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_IAC_3));
mb.Hreg(0x9c8d, hexbytes[1]);
mb.Hreg(0x9c8e, hexbytes[0]);
value = (inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_UAC_1N));
value = ((inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_UAC_1N) != 0 ? inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_UAC_1N) : inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_UAC)));
mb.Hreg(0x9c8f, hexbytes[1]);
mb.Hreg(0x9c90, hexbytes[0]);
value = (inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_UAC_1N));
Expand Down Expand Up @@ -139,7 +142,7 @@ void ModbusDtuClass::loop()
value = (inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_PAC)*-1);
mb.Hreg(0x9ca1, hexbytes[1]);
mb.Hreg(0x9ca2, hexbytes[0]);
value = ((inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_IAC_1)) * (inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_UAC_1N)) *-1);
value = (((inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_IAC_1) != 0 ? inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_IAC_1) : inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_IAC))) * (inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_UAC_1N)) *-1);
mb.Hreg(0x9ca3, hexbytes[1]);
mb.Hreg(0x9ca4, hexbytes[0]);
value = ((inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_IAC_2)) * (inv->Statistics()->getChannelFieldValue(TYPE_AC, CH0, FLD_UAC_2N)) *-1);
Expand Down Expand Up @@ -182,12 +185,12 @@ void ModbusDtuClass::loop()
} else {
mb.addHreg(0x9cc1, 0);
mb.addHreg(0x9cc2, 0);
mb.Hreg(0x9cc1, hexbytes[1]);
mb.Hreg(0x9cc2, hexbytes[0]);
}
mb.Hreg(0x9cc1, hexbytes[1]);
mb.Hreg(0x9cc2, hexbytes[0]);
}
}
}
}
} else {
float value;
uint16_t *hexbytes = (uint16_t *)&value;
Expand All @@ -201,11 +204,12 @@ void ModbusDtuClass::loop()
} else {
mb.addHreg(0x9cc1, 0);
mb.addHreg(0x9cc2, 0);
mb.Hreg(0x9cc1, hexbytes[1]);
mb.Hreg(0x9cc2, hexbytes[0]);
}
mb.Hreg(0x9cc1, hexbytes[1]);
mb.Hreg(0x9cc2, hexbytes[0]);
}
}
_lastPublish = millis();
// MessageOutput.printf("Modbus end %lu\r\n", millis());
}
yield();
mb.task();
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void setup()
// Initialize Modbus
MessageOutput.print(F("Initialize Modbus... "));
ModbusDtu.init();
MessageOutput.println(F("done"));
MessageOutput.print(F("Initialize WatchDog... "));
WatchDogDtu.init();
MessageOutput.println(F("done"));
Expand Down

0 comments on commit 6bc9acb

Please sign in to comment.