Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pipelka committed Jan 19, 2024
1 parent 222d6b0 commit 3f96304
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
2 changes: 2 additions & 0 deletions include/ModbusSunSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class ModbusSunSpecClass : protected ModbusTCP {

uint8_t getPhaseCount();

bool getIsAllEnabledProducing();

SUNSPEC_INVERTER_CONFIG_T* getConfig(uint64_t serial);

private:
Expand Down
56 changes: 41 additions & 15 deletions src/ModbusSunSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,26 @@ void ModbusSunSpecClass::loopPowerLimit() {

void ModbusSunSpecClass::loop() {
const CONFIG_T& config = Configuration.get();
bool allProducing = getIsAllEnabledProducing();

// Status
if(!SunPosition.isDayPeriod()) {
HregU16(40107, 2);
}
else if(Datastore.getIsAtLeastOneReachable()) {
HregU16(40107, 3);
}
else if(allProducing) {
bool throttled = (Hreg(40158) == 1) && (Hreg(40154) < 100);
HregU16(40107, throttled ? 5 : 4);
}
else {
HregU16(40107, 8);
}

if(!allProducing) {
return;
}

if(config.SunSpec.RemoteControl) {
loopPowerLimit();
Expand Down Expand Up @@ -343,21 +363,6 @@ void ModbusSunSpecClass::loop() {
HregU16(40104, max_temp); // Temperature
HregU16(40105, max_temp); // Temperature
HregU16(40124, getTotalMaxPower()); // WRtg

// Status
if(!SunPosition.isDayPeriod()) {
HregU16(40107, 2);
}
else if(Datastore.getIsAtLeastOneReachable()) {
HregU16(40107, 3);
}
else if(Datastore.getIsAtLeastOneProducing()) {
bool throttled = (Hreg(40158) == 1) && (Hreg(40154) < 100);
HregU16(40107, throttled ? 5 : 4);
}
else {
HregU16(40107, 8);
}
}

void ModbusSunSpecClass::setPowerLimit(uint16_t limit_pct, uint16_t timeout_sec) {
Expand Down Expand Up @@ -398,6 +403,27 @@ void ModbusSunSpecClass::setPowerLimit(uint16_t limit_pct, uint16_t timeout_sec)
MessageOutput.printf("New Total Power: %uW\r\n", total_power);
}

bool ModbusSunSpecClass::getIsAllEnabledProducing() {
const CONFIG_T& config = Configuration.get();
for (auto &conf : config.SunSpec.Inverter) {
if (!conf.Enabled || conf.Serial == 0) {
continue;
}

auto inv = Hoymiles.getInverterBySerial(conf.Serial);

if (inv == nullptr) {
return false;
}

if(!inv->isProducing()) {
return false;
}
}

return true;
}

uint16_t ModbusSunSpecClass::getTotalMaxPower() {
uint16_t max_power{0};
const CONFIG_T& config = Configuration.get();
Expand Down

0 comments on commit 3f96304

Please sign in to comment.