Skip to content

Commit

Permalink
Merge pull request #532 from KipK/#452
Browse files Browse the repository at this point in the history
fix #452 reevaluate claims if amps > pilot
  • Loading branch information
jeremypoulter authored Feb 6, 2023
2 parents 7c2a177 + 209cc1b commit 1059f05
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
25 changes: 22 additions & 3 deletions src/evse_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,20 @@ void EvseMonitor::updateEvseState(uint8_t evse_state, uint8_t pilot_state, uint3
}
}

void EvseMonitor::verifyPilot() {
// After some state changes the OpenEVSE module compiled with PP_AUTO_AMPACITY will reset to the maximum pilot level, so reset to what we expect
_openevse.getCurrentCapacity([this](int ret, long min_current, long max_hardware_current, long pilot, long max_configured_current)
{
if(RAPI_RESPONSE_OK == ret && pilot > getPilot())
{
DBUGLN("#### Pilot is wrong set again");
DBUGVAR(pilot);
DBUGVAR(getPilot());
setPilot(getPilot(), true);
}
});
}

void EvseMonitor::updateCurrentSettings(long min_current, long max_hardware_current, long pilot, long max_configured_current)
{
DBUGF("min_current = %ld, pilot = %ld, max_configured_current = %ld, max_hardware_current = %ld", min_current, pilot, max_configured_current, max_hardware_current);
Expand All @@ -320,7 +334,6 @@ void EvseMonitor::updateCurrentSettings(long min_current, long max_hardware_curr
_max_configured_current = max_configured_current;
}


unsigned long EvseMonitor::loop(MicroTasks::WakeReason reason)
{
DBUG("EVSE monitor woke: ");
Expand Down Expand Up @@ -359,6 +372,12 @@ unsigned long EvseMonitor::loop(MicroTasks::WakeReason reason)
getEnergyFromEvse();
}

// Check if pilot is wrong ( solve OpenEvse fw compiled with -D PP_AUTO_AMPACITY)
if (isCharging()){
verifyPilot();
}


_count ++;

return EVSE_MONITOR_POLL_TIME;
Expand Down Expand Up @@ -454,7 +473,7 @@ void EvseMonitor::disable()
});
}

void EvseMonitor::setPilot(long amps, std::function<void(int ret)> callback)
void EvseMonitor::setPilot(long amps, bool force, std::function<void(int ret)> callback)
{
// limit `amps` to the software limit
if(amps > _max_configured_current) {
Expand All @@ -464,7 +483,7 @@ void EvseMonitor::setPilot(long amps, std::function<void(int ret)> callback)
amps = _min_current;
}

if(amps == _pilot)
if(amps == _pilot && !force)
{
if(callback) {
callback(RAPI_RESPONSE_OK);
Expand Down
3 changes: 2 additions & 1 deletion src/evse_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class EvseMonitor : public MicroTasks::Task

void setMaxConfiguredCurrent(long amps);

void setPilot(long amps, std::function<void(int ret)> callback = NULL);
void setPilot(long amps, bool force=false, std::function<void(int ret)> callback = NULL);
void setVoltage(double volts, std::function<void(int ret)> callback = NULL);
void setServiceLevel(ServiceLevel level, std::function<void(int ret)> callback = NULL);
void configureCurrentSensorScale(long scale, long offset, std::function<void(int ret)> callback = NULL);
Expand All @@ -209,6 +209,7 @@ class EvseMonitor : public MicroTasks::Task
void enableStuckRelayCheck(bool enabled, std::function<void(int ret)> callback = NULL);
void enableVentRequired(bool enabled, std::function<void(int ret)> callback = NULL);
void enableTemperatureCheck(bool enabled, std::function<void(int ret)> callback = NULL);
void verifyPilot();

uint8_t getEvseState() {
return _state.getEvseState();
Expand Down

0 comments on commit 1059f05

Please sign in to comment.