Skip to content

Commit

Permalink
debug printouts, removed unnecessary check causing inverter to toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
MalteSchm committed Apr 29, 2023
1 parent dae4c6f commit db4125a
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/PowerLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

PowerLimiterClass PowerLimiter;

#define POWER_LIMITER_DEBUG

void PowerLimiterClass::init()
{
}
Expand All @@ -30,29 +32,41 @@ void PowerLimiterClass::loop()
return;
}

#ifdef POWER_LIMITER_DEBUG
MessageOutput.println("[PowerLimiterClass::loop] ******************* ENTER **********************");
#endif

_lastLoop = millis();

std::shared_ptr<InverterAbstract> inverter = Hoymiles.getInverterByPos(config.PowerLimiter_InverterId);
if (inverter == nullptr || !inverter->isReachable()) {
#ifdef POWER_LIMITER_DEBUG
MessageOutput.println("[PowerLimiterClass::loop] ******************* No inverter found");
#endif
return;
}

// Make sure inverter is turned off if PL is disabled by user/MQTT
// Make sure inverter is turned off when low battery threshold is reached
if (((!config.PowerLimiter_Enabled || _disabled) && _plState != SHUTDOWN)
|| isStopThresholdReached(inverter)) {
if (((!config.PowerLimiter_Enabled || _disabled) && _plState != SHUTDOWN)) {
if (inverter->isProducing()) {
MessageOutput.printf("PL initiated inverter shutdown.\r\n");
inverter->sendActivePowerControlRequest(config.PowerLimiter_LowerPowerLimit, PowerLimitControlType::AbsolutNonPersistent);
inverter->sendPowerControlRequest(false);
} else {
_plState = SHUTDOWN;
}
#ifdef POWER_LIMITER_DEBUG
MessageOutput.printf("[PowerLimiterClass::loop] ******************* PL put into shutdown, _plState = %i\r\n", _plState);
#endif
return;
}

// Return if power limiter is disabled
if (!config.PowerLimiter_Enabled || _disabled) {
#ifdef POWER_LIMITER_DEBUG
MessageOutput.printf("[PowerLimiterClass::loop] ******************* PL disabled\r\n");
#endif
return;
}

Expand All @@ -65,6 +79,9 @@ void PowerLimiterClass::loop()
MessageOutput.println("[PowerLimiterClass::loop] Power Meter/Inverter values too old. Using 0W (i.e. disable inverter)");
inverter->sendActivePowerControlRequest(config.PowerLimiter_LowerPowerLimit, PowerLimitControlType::AbsolutNonPersistent);
inverter->sendPowerControlRequest(false);
#ifdef POWER_LIMITER_DEBUG
MessageOutput.printf("[PowerLimiterClass::loop] ******************* PL safety shutdown, update times exceeded PM: %li, Inverter: %li \r\n", millis() - PowerMeter.getLastPowerMeterUpdate(), millis() - inverter->Statistics()->getLastUpdate());
#endif
return;
}

Expand All @@ -76,6 +93,9 @@ void PowerLimiterClass::loop()
// as the Hoymiles MPPT might not react immediately.
if (inverter->Statistics()->getLastUpdate() <= _lastLimitSetTime
|| PowerMeter.getLastPowerMeterUpdate() <= (_lastLimitSetTime + 3000)) {
#ifdef POWER_LIMITER_DEBUG
MessageOutput.printf("[PowerLimiterClass::loop] ******************* PL inverter updates PM: %i, Inverter: %i \r\n", PowerMeter.getLastPowerMeterUpdate() - (_lastLimitSetTime + 3000), inverter->Statistics()->getLastUpdate() - _lastLimitSetTime);
#endif
return;
}

Expand Down Expand Up @@ -116,10 +136,18 @@ void PowerLimiterClass::loop()
_batteryDischargeEnabled = true;
}
}

// Calculate and set Power Limit
int32_t newPowerLimit = calcPowerLimit(inverter, canUseDirectSolarPower(), _batteryDischargeEnabled);
setNewPowerLimit(inverter, newPowerLimit);
#ifdef POWER_LIMITER_DEBUG
MessageOutput.printf("[PowerLimiterClass::loop] Status: SolarPT enabled %i, Drain Strategy: %i, canUseDirectSolarPower: %i, Batt discharge: %i\r\n",
config.PowerLimiter_SolarPassThroughEnabled, config.PowerLimiter_BatteryDrainStategy, canUseDirectSolarPower(), _batteryDischargeEnabled);
MessageOutput.printf("[PowerLimiterClass::loop] Status: StartTH %i, StopTH: %i, loadCorrectedV %f\r\n",
isStartThresholdReached(inverter), isStopThresholdReached(inverter), getLoadCorrectedVoltage(inverter));
MessageOutput.printf("[PowerLimiterClass::loop] Status Batt: Ena: %i, SOC: %i, StartTH: %i, StopTH: %i, LastUpdate: %li\r\n",
config.Battery_Enabled, Battery.stateOfCharge, config.PowerLimiter_BatterySocStartThreshold, config.PowerLimiter_BatterySocStopThreshold, millis() - Battery.stateOfChargeLastUpdate);
MessageOutput.printf("[PowerLimiterClass::loop] ******************* Leaving PL, PL set to: %i, SP: %i, Batt: %i, PM: %f\r\n", newPowerLimit, canUseDirectSolarPower(), _batteryDischargeEnabled, round(PowerMeter.getPowerTotal()));
#endif
}

uint8_t PowerLimiterClass::getPowerLimiterState() {
Expand Down

0 comments on commit db4125a

Please sign in to comment.