From 9cc3276e80aa8cd4ee58581007ec6e173ec8cf97 Mon Sep 17 00:00:00 2001 From: Bradley Neild <46658771+BradleyNeild@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:08:41 +0200 Subject: [PATCH] Added EVSE-side plug API Will allow us to add an EVSE-side plug button to the dashboard in the future --- src/api.cpp | 4 ++++ src/evse.cpp | 16 +++++++++++++++- src/evse.h | 6 ++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/api.cpp b/src/api.cpp index f07d225..955415f 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -83,6 +83,9 @@ int mocpp_api_call(const char *endpoint, MicroOcpp::Method method, const char *b if (request.containsKey("evPlugged")) { evse->setEvPlugged(request["evPlugged"]); } + if (request.containsKey("evsePlugged")) { + evse->setEvsePlugged(request["evsePlugged"]); + } if (request.containsKey("evReady")) { evse->setEvReady(request["evReady"]); } @@ -92,6 +95,7 @@ int mocpp_api_call(const char *endpoint, MicroOcpp::Method method, const char *b } response["evPlugged"] = evse->getEvPlugged(); + response["evsePlugged"] = evse->getEvsePlugged(); response["evReady"] = evse->getEvReady(); response["evseReady"] = evse->getEvseReady(); response["chargePointStatus"] = evse->getOcppStatus(); diff --git a/src/evse.cpp b/src/evse.cpp index 59269e8..ff85000 100644 --- a/src/evse.cpp +++ b/src/evse.cpp @@ -54,6 +54,9 @@ void Evse::setup() { snprintf(key, 30, "evPlugged_cId_%u", connectorId); trackEvPluggedKey = key; trackEvPluggedBool = MicroOcpp::declareConfiguration(trackEvPluggedKey.c_str(), false, SIMULATOR_FN, false, false, false); + snprintf(key, 30, "evsePlugged_cId_%u", connectorId); + trackEvsePluggedKey = key; + trackEvsePluggedBool = MicroOcpp::declareConfiguration(trackEvsePluggedKey.c_str(), false, SIMULATOR_FN, false, false, false); snprintf(key, 30, "evReady_cId_%u", connectorId); trackEvReadyKey = key; trackEvReadyBool = MicroOcpp::declareConfiguration(trackEvReadyKey.c_str(), false, SIMULATOR_FN, false, false, false); @@ -139,7 +142,7 @@ void Evse::loop() { } } - bool simulate_isCharging = ocppPermitsCharge(connectorId) && trackEvPluggedBool->getBool() && trackEvReadyBool->getBool() && trackEvseReadyBool->getBool(); + bool simulate_isCharging = ocppPermitsCharge(connectorId) && trackEvPluggedBool->getBool() && trackEvsePluggedBool->getBool() && trackEvReadyBool->getBool() && trackEvseReadyBool->getBool(); simulate_isCharging &= limit_power >= 720.f; //minimum charging current is 6A (720W for 120V grids) according to J1772 @@ -209,6 +212,17 @@ bool Evse::getEvPlugged() { return trackEvPluggedBool->getBool(); } +void Evse::setEvsePlugged(bool plugged) { + if (!trackEvsePluggedBool) return; + trackEvsePluggedBool->setBool(plugged); + MicroOcpp::configuration_save(); +} + +bool Evse::getEvsePlugged() { + if (!trackEvsePluggedBool) return false; + return trackEvsePluggedBool->getBool(); +} + void Evse::setEvReady(bool ready) { if (!trackEvReadyBool) return; trackEvReadyBool->setBool(ready); diff --git a/src/evse.h b/src/evse.h index 920ecc5..399652d 100644 --- a/src/evse.h +++ b/src/evse.h @@ -17,6 +17,8 @@ class Evse { std::shared_ptr trackEvPluggedBool; std::string trackEvPluggedKey; + std::shared_ptr trackEvsePluggedBool; + std::string trackEvsePluggedKey; std::shared_ptr trackEvReadyBool; std::string trackEvReadyKey; std::shared_ptr trackEvseReadyBool; @@ -43,6 +45,10 @@ class Evse { bool getEvPlugged(); + void setEvsePlugged(bool plugged); + + bool getEvsePlugged(); + void setEvReady(bool ready); bool getEvReady();