Skip to content

Commit

Permalink
fix cast error with unsigned int
Browse files Browse the repository at this point in the history
 which results in wrong power limit settings if values become < 0 due
 to power export to the grid.
  • Loading branch information
helgeerbe committed Mar 16, 2023
1 parent 9214897 commit 04c7e4f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ struct CONFIG_T {
bool PowerLimiter_IsInverterBehindPowerMeter;
uint8_t PowerLimiter_InverterId;
uint8_t PowerLimiter_InverterChannelId;
uint32_t PowerLimiter_TargetPowerConsumption;
uint32_t PowerLimiter_TargetPowerConsumptionHysteresis;
uint32_t PowerLimiter_LowerPowerLimit;
uint32_t PowerLimiter_UpperPowerLimit;
int32_t PowerLimiter_TargetPowerConsumption;
int32_t PowerLimiter_TargetPowerConsumptionHysteresis;
int32_t PowerLimiter_LowerPowerLimit;
int32_t PowerLimiter_UpperPowerLimit;
uint32_t PowerLimiter_BatterySocStartThreshold;
uint32_t PowerLimiter_BatterySocStopThreshold;
float PowerLimiter_VoltageStartThreshold;
Expand Down
5 changes: 3 additions & 2 deletions src/PowerLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ int32_t PowerLimiterClass::calcPowerLimit(std::shared_ptr<InverterAbstract> inve
uint32_t victronChargePower = this->getDirectSolarPower();
uint32_t adjustedVictronChargePower = victronChargePower * (efficency > 0.0 ? (efficency / 100.0) : 1.0); // if inverter is off, use 1.0

MessageOutput.printf("[PowerLimiterClass::loop] victronChargePower: %d, efficiency: %.2f, consumeSolarPowerOnly: %s \r\n", victronChargePower, efficency, consumeSolarPowerOnly ? "true" : "false");
MessageOutput.printf("[PowerLimiterClass::loop] victronChargePower: %d, efficiency: %.2f, consumeSolarPowerOnly: %s, powerConsumption: %d \r\n",
victronChargePower, efficency, consumeSolarPowerOnly ? "true" : "false", newPowerLimit);

if (millis() - _lastPowerMeterUpdate < (30 * 1000)) {
if (config.PowerLimiter_IsInverterBehindPowerMeter) {
Expand All @@ -230,7 +231,7 @@ int32_t PowerLimiterClass::calcPowerLimit(std::shared_ptr<InverterAbstract> inve

newPowerLimit -= config.PowerLimiter_TargetPowerConsumption;

uint32_t upperPowerLimit = config.PowerLimiter_UpperPowerLimit;
int32_t upperPowerLimit = config.PowerLimiter_UpperPowerLimit;
if (consumeSolarPowerOnly && (upperPowerLimit > adjustedVictronChargePower)) {
// Battery voltage too low, use Victron solar power (corrected by efficency factor) only
upperPowerLimit = adjustedVictronChargePower;
Expand Down

0 comments on commit 04c7e4f

Please sign in to comment.