diff --git a/src/evse_man.cpp b/src/evse_man.cpp index 1cd69c20..3553f717 100644 --- a/src/evse_man.cpp +++ b/src/evse_man.cpp @@ -311,6 +311,10 @@ void EvseManager::setSleepForDisable(bool sleepForDisable) } } +void EvseManager::unlock() { + _monitor.unlock(); +} + unsigned long EvseManager::loop(MicroTasks::WakeReason reason) { DBUG("EVSE manager woke: "); diff --git a/src/evse_man.h b/src/evse_man.h index ca5ba6cb..599a3431 100644 --- a/src/evse_man.h +++ b/src/evse_man.h @@ -297,6 +297,9 @@ class EvseManager : public MicroTasks::Task bool isVehicleConnected() { return _monitor.isVehicleConnected(); } + bool isBootLocked() { + return _monitor.isBootLocked(); + } bool isError() { return _monitor.isError(); } @@ -482,6 +485,9 @@ class EvseManager : public MicroTasks::Task } void setSleepForDisable(bool sleepForDisable); + // unlock openevse fw compiled with BOOTLOCK + void unlock(); + // Temp until everything uses EvseManager RapiSender &getSender() { return _sender; diff --git a/src/evse_monitor.cpp b/src/evse_monitor.cpp index 3bd4873c..72670cad 100644 --- a/src/evse_monitor.cpp +++ b/src/evse_monitor.cpp @@ -253,27 +253,6 @@ void EvseMonitor::evseBoot(const char *firmware) _openevse.heartbeatEnable(EVSE_HEATBEAT_INTERVAL, EVSE_HEARTBEAT_CURRENT, [this](int ret, int interval, int current, int triggered) { _heartbeat = RAPI_RESPONSE_OK == ret; }); - - // ESP32_WiFi handle OpenEvse state, so let first put it to disabled before unlocking - if (config_pause_uses_disabled()) { - disable(); - } - else { - sleep(); - } - - // Unlock OpenEVSE if compiled with BOOTLOCK - _openevse.clearBootLock([this](int ret) - { - if(RAPI_RESPONSE_OK == ret) - { - DBUGF("Unlocked OpenEVSE"); - } - else { - DBUGF("Unlock OpenEVSE failed"); - } - - }); } void EvseMonitor::updateEvseState(uint8_t evse_state, uint8_t pilot_state, uint32_t vflags) @@ -368,7 +347,7 @@ unsigned long EvseMonitor::loop(MicroTasks::WakeReason reason) if (isCharging()){ verifyPilot(); } - + _count ++; return EVSE_MONITOR_POLL_TIME; @@ -431,6 +410,20 @@ EvseMonitor::ServiceLevel EvseMonitor::getActualServiceLevel() ServiceLevel::L1; } +void EvseMonitor::unlock() { + // Unlock OpenEVSE if compiled with BOOTLOCK + _openevse.clearBootLock([this](int ret) + { + if(RAPI_RESPONSE_OK == ret) + { + DBUGF("Unlocked OpenEVSE"); + } + else { + DBUGF("Unlock OpenEVSE failed"); + } + + }); +} void EvseMonitor::enable() { OpenEVSE.enable([this](int ret) diff --git a/src/evse_monitor.h b/src/evse_monitor.h index a612b772..04b74d68 100644 --- a/src/evse_monitor.h +++ b/src/evse_monitor.h @@ -60,6 +60,9 @@ class EvseMonitor : public MicroTasks::Task bool isVehicleConnected() { return OPENEVSE_VFLAG_EV_CONNECTED == (getFlags() & OPENEVSE_VFLAG_EV_CONNECTED); } + bool isBootLocked() { + return OPENEVSE_VFLAG_BOOT_LOCK == (getFlags() & OPENEVSE_VFLAG_BOOT_LOCK); + } }; class DataReady : public MicroTasks::Event @@ -188,7 +191,7 @@ class EvseMonitor : public MicroTasks::Task ~EvseMonitor(); bool begin(RapiSender &sender); - + void unlock(); void enable(); void sleep(); void disable(); @@ -232,6 +235,9 @@ class EvseMonitor : public MicroTasks::Task bool isVehicleConnected() { return _state.isVehicleConnected(); } + bool isBootLocked() { + return _state.isBootLocked(); + } double getAmps() { return _amp; } diff --git a/src/main.cpp b/src/main.cpp index 65afac1d..be1562e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -200,6 +200,11 @@ loop() { import_timers(&scheduler); } + // unlock openevse fw compiled with BOOTLOCK + if (evse.isBootLocked()) { + evse.unlock(); + DBUGLN("Unlocked BOOTLOCK"); + } // ------------------------------------------------------------------- // Do these things once every 2s