From 5e69c8599c726786fdbff4a3489895429ce748b5 Mon Sep 17 00:00:00 2001 From: KipK Date: Sun, 29 Jan 2023 16:07:55 +0100 Subject: [PATCH 1/5] fix #452 . Check if Pilot from Evse and Pilot from evseMonitor are the same, if not reset. Temporary fix EmonEvse firmware and other compiled with PP_AUTO_AMPACITY where starting at full charge instead of configured one. --- openevse-gui-v2 | 1 + src/evse_monitor.cpp | 27 +++++++++++++++++++++++++-- src/evse_monitor.h | 3 +++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 160000 openevse-gui-v2 diff --git a/openevse-gui-v2 b/openevse-gui-v2 new file mode 160000 index 00000000..3f2c8af5 --- /dev/null +++ b/openevse-gui-v2 @@ -0,0 +1 @@ +Subproject commit 3f2c8af5294e4c4a25140c5229a0c6659ce0626b diff --git a/src/evse_monitor.cpp b/src/evse_monitor.cpp index c705d0f9..ebc24240 100644 --- a/src/evse_monitor.cpp +++ b/src/evse_monitor.cpp @@ -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), @@ -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); @@ -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: "); @@ -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; @@ -464,7 +487,7 @@ void EvseMonitor::setPilot(long amps, std::function callback) amps = _min_current; } - if(amps == _pilot) + if(amps == _pilot && !_pilot_is_wrong) { if(callback) { callback(RAPI_RESPONSE_OK); diff --git a/src/evse_monitor.h b/src/evse_monitor.h index f60ac359..c8a06791 100644 --- a/src/evse_monitor.h +++ b/src/evse_monitor.h @@ -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 @@ -209,6 +211,7 @@ class EvseMonitor : public MicroTasks::Task void enableStuckRelayCheck(bool enabled, std::function callback = NULL); void enableVentRequired(bool enabled, std::function callback = NULL); void enableTemperatureCheck(bool enabled, std::function callback = NULL); + void verifyPilot(); uint8_t getEvseState() { return _state.getEvseState(); From 6eb79ac132fd3f76e8d1672c112233430f7525f0 Mon Sep 17 00:00:00 2001 From: KipK Date: Thu, 2 Feb 2023 17:02:06 +0100 Subject: [PATCH 2/5] remove useless log --- src/evse_monitor.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/evse_monitor.cpp b/src/evse_monitor.cpp index ebc24240..14fa2b3e 100644 --- a/src/evse_monitor.cpp +++ b/src/evse_monitor.cpp @@ -317,13 +317,11 @@ 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"); + DBUGVAR(pilot); + DBUGVAR(getPilot()); _pilot_is_wrong = true; setPilot(getPilot()); _pilot_is_wrong = false; From bbcbb4148008c374daa88711070b3d2c9f9b8d13 Mon Sep 17 00:00:00 2001 From: KipK Date: Thu, 2 Feb 2023 21:43:22 +0100 Subject: [PATCH 3/5] remove verifyPilot() from updateEvseState ( useless as evse will check later the cable ampacity ) --- src/evse_monitor.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/evse_monitor.cpp b/src/evse_monitor.cpp index 14fa2b3e..d3a9b651 100644 --- a/src/evse_monitor.cpp +++ b/src/evse_monitor.cpp @@ -309,7 +309,6 @@ void EvseMonitor::updateEvseState(uint8_t evse_state, uint8_t pilot_state, uint3 } _session_complete.update(getFlags()); }); - verifyPilot(); } } From 525feb4c68fd43adccc5df8eb973cfd8f26d0463 Mon Sep 17 00:00:00 2001 From: KipK Date: Sun, 5 Feb 2023 00:51:27 +0100 Subject: [PATCH 4/5] reviewed change --- src/evse_monitor.cpp | 15 +++++++-------- src/evse_monitor.h | 4 +--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/evse_monitor.cpp b/src/evse_monitor.cpp index d3a9b651..3ceb344b 100644 --- a/src/evse_monitor.cpp +++ b/src/evse_monitor.cpp @@ -163,7 +163,6 @@ 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), @@ -316,14 +315,12 @@ 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()) + if(RAPI_RESPONSE_OK == ret && pilot > getPilot()) { DBUGLN("#### Pilot is wrong set again"); DBUGVAR(pilot); DBUGVAR(getPilot()); - _pilot_is_wrong = true; - setPilot(getPilot()); - _pilot_is_wrong = false; + setPilot(getPilot(), true); } }); } @@ -376,8 +373,10 @@ unsigned long EvseMonitor::loop(MicroTasks::WakeReason reason) } // Check if pilot is wrong ( solve OpenEvse fw compiled with -D PP_AUTO_AMPACITY) - if (isCharging()) + if (isCharging()){ verifyPilot(); + } + _count ++; @@ -474,7 +473,7 @@ void EvseMonitor::disable() }); } -void EvseMonitor::setPilot(long amps, std::function callback) +void EvseMonitor::setPilot(long amps, bool force=false, std::function callback) { // limit `amps` to the software limit if(amps > _max_configured_current) { @@ -484,7 +483,7 @@ void EvseMonitor::setPilot(long amps, std::function callback) amps = _min_current; } - if(amps == _pilot && !_pilot_is_wrong) + if(amps == _pilot && !force) { if(callback) { callback(RAPI_RESPONSE_OK); diff --git a/src/evse_monitor.h b/src/evse_monitor.h index c8a06791..185a63d9 100644 --- a/src/evse_monitor.h +++ b/src/evse_monitor.h @@ -155,8 +155,6 @@ class EvseMonitor : public MicroTasks::Task char _firmware_version[32]; char _serial[16]; - bool _pilot_is_wrong; - #ifdef ENABLE_MCP9808 Adafruit_MCP9808 _mcp9808; #endif @@ -200,7 +198,7 @@ class EvseMonitor : public MicroTasks::Task void setMaxConfiguredCurrent(long amps); - void setPilot(long amps, std::function callback = NULL); + void setPilot(long amps, bool force=false, std::function callback = NULL); void setVoltage(double volts, std::function callback = NULL); void setServiceLevel(ServiceLevel level, std::function callback = NULL); void configureCurrentSensorScale(long scale, long offset, std::function callback = NULL); From 209cc1bca7a30525459ed5c6151149ec8146bf31 Mon Sep 17 00:00:00 2001 From: KipK Date: Sun, 5 Feb 2023 01:43:42 +0100 Subject: [PATCH 5/5] fix force variable initialised twice --- src/evse_monitor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/evse_monitor.cpp b/src/evse_monitor.cpp index 3ceb344b..11e07a28 100644 --- a/src/evse_monitor.cpp +++ b/src/evse_monitor.cpp @@ -473,7 +473,7 @@ void EvseMonitor::disable() }); } -void EvseMonitor::setPilot(long amps, bool force=false, std::function callback) +void EvseMonitor::setPilot(long amps, bool force, std::function callback) { // limit `amps` to the software limit if(amps > _max_configured_current) {