Skip to content

Commit 3a58611

Browse files
authored
Merge pull request #28 from BradleyNeild/main
Added EVSE-side plug API
2 parents 9d119f1 + 9cc3276 commit 3a58611

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/api.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ int mocpp_api_call(const char *endpoint, MicroOcpp::Method method, const char *b
8383
if (request.containsKey("evPlugged")) {
8484
evse->setEvPlugged(request["evPlugged"]);
8585
}
86+
if (request.containsKey("evsePlugged")) {
87+
evse->setEvsePlugged(request["evsePlugged"]);
88+
}
8689
if (request.containsKey("evReady")) {
8790
evse->setEvReady(request["evReady"]);
8891
}
@@ -92,6 +95,7 @@ int mocpp_api_call(const char *endpoint, MicroOcpp::Method method, const char *b
9295
}
9396

9497
response["evPlugged"] = evse->getEvPlugged();
98+
response["evsePlugged"] = evse->getEvsePlugged();
9599
response["evReady"] = evse->getEvReady();
96100
response["evseReady"] = evse->getEvseReady();
97101
response["chargePointStatus"] = evse->getOcppStatus();

src/evse.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ void Evse::setup() {
5454
snprintf(key, 30, "evPlugged_cId_%u", connectorId);
5555
trackEvPluggedKey = key;
5656
trackEvPluggedBool = MicroOcpp::declareConfiguration(trackEvPluggedKey.c_str(), false, SIMULATOR_FN, false, false, false);
57+
snprintf(key, 30, "evsePlugged_cId_%u", connectorId);
58+
trackEvsePluggedKey = key;
59+
trackEvsePluggedBool = MicroOcpp::declareConfiguration(trackEvsePluggedKey.c_str(), false, SIMULATOR_FN, false, false, false);
5760
snprintf(key, 30, "evReady_cId_%u", connectorId);
5861
trackEvReadyKey = key;
5962
trackEvReadyBool = MicroOcpp::declareConfiguration(trackEvReadyKey.c_str(), false, SIMULATOR_FN, false, false, false);
@@ -139,7 +142,7 @@ void Evse::loop() {
139142
}
140143
}
141144

142-
bool simulate_isCharging = ocppPermitsCharge(connectorId) && trackEvPluggedBool->getBool() && trackEvReadyBool->getBool() && trackEvseReadyBool->getBool();
145+
bool simulate_isCharging = ocppPermitsCharge(connectorId) && trackEvPluggedBool->getBool() && trackEvsePluggedBool->getBool() && trackEvReadyBool->getBool() && trackEvseReadyBool->getBool();
143146

144147
simulate_isCharging &= limit_power >= 720.f; //minimum charging current is 6A (720W for 120V grids) according to J1772
145148

@@ -209,6 +212,17 @@ bool Evse::getEvPlugged() {
209212
return trackEvPluggedBool->getBool();
210213
}
211214

215+
void Evse::setEvsePlugged(bool plugged) {
216+
if (!trackEvsePluggedBool) return;
217+
trackEvsePluggedBool->setBool(plugged);
218+
MicroOcpp::configuration_save();
219+
}
220+
221+
bool Evse::getEvsePlugged() {
222+
if (!trackEvsePluggedBool) return false;
223+
return trackEvsePluggedBool->getBool();
224+
}
225+
212226
void Evse::setEvReady(bool ready) {
213227
if (!trackEvReadyBool) return;
214228
trackEvReadyBool->setBool(ready);

src/evse.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class Evse {
1717

1818
std::shared_ptr<MicroOcpp::Configuration> trackEvPluggedBool;
1919
std::string trackEvPluggedKey;
20+
std::shared_ptr<MicroOcpp::Configuration> trackEvsePluggedBool;
21+
std::string trackEvsePluggedKey;
2022
std::shared_ptr<MicroOcpp::Configuration> trackEvReadyBool;
2123
std::string trackEvReadyKey;
2224
std::shared_ptr<MicroOcpp::Configuration> trackEvseReadyBool;
@@ -43,6 +45,10 @@ class Evse {
4345

4446
bool getEvPlugged();
4547

48+
void setEvsePlugged(bool plugged);
49+
50+
bool getEvsePlugged();
51+
4652
void setEvReady(bool ready);
4753

4854
bool getEvReady();

0 commit comments

Comments
 (0)