Skip to content

Commit

Permalink
fix #452 . Check if Pilot from Evse and Pilot from evseMonitor are th…
Browse files Browse the repository at this point in the history
…e same, if not reset.

Temporary fix EmonEvse firmware and other compiled with PP_AUTO_AMPACITY where starting at full charge instead of configured one.
  • Loading branch information
KipK committed Feb 2, 2023
1 parent 751d837 commit 5e69c85
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions openevse-gui-v2
Submodule openevse-gui-v2 added at 3f2c8a
27 changes: 25 additions & 2 deletions src/evse_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ EvseMonitor::EvseMonitor(OpenEVSEClass &openevse) :
_stuck_count(0),
_min_current(0),
_pilot(0),
_pilot_is_wrong(false),
_max_configured_current(0),
_max_hardware_current(80),
_data_ready(EVSE_MONITOR_DATA_READY),
Expand Down Expand Up @@ -308,9 +309,28 @@ void EvseMonitor::updateEvseState(uint8_t evse_state, uint8_t pilot_state, uint3
}
_session_complete.update(getFlags());
});
verifyPilot();
}
}

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)
{
DBUGLN("Check pilot is ok");
DBUGVAR(pilot);
DBUGVAR(getPilot());

if(RAPI_RESPONSE_OK == ret && pilot != getPilot())
{
DBUGLN("#### Pilot is wrong set again");
_pilot_is_wrong = true;
setPilot(getPilot());
_pilot_is_wrong = false;
}
});
}

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 +340,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 +378,10 @@ 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 @@ -464,7 +487,7 @@ void EvseMonitor::setPilot(long amps, std::function<void(int ret)> callback)
amps = _min_current;
}

if(amps == _pilot)
if(amps == _pilot && !_pilot_is_wrong)
{
if(callback) {
callback(RAPI_RESPONSE_OK);
Expand Down
3 changes: 3 additions & 0 deletions src/evse_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class EvseMonitor : public MicroTasks::Task
char _firmware_version[32];
char _serial[16];

bool _pilot_is_wrong;

#ifdef ENABLE_MCP9808
Adafruit_MCP9808 _mcp9808;
#endif
Expand Down Expand Up @@ -209,6 +211,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 5e69c85

Please sign in to comment.