Skip to content

Commit ee9bea4

Browse files
committed
feedback Jeremy
1 parent f24cacb commit ee9bea4

File tree

8 files changed

+31
-106
lines changed

8 files changed

+31
-106
lines changed

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ lib_deps =
4343
4444
4545
46-
https://github.com/matth-x/ArduinoOcpp
46+
matth-x/ArduinoOcpp@0.0.2
4747
lib_ignore = WebSockets ; ArduinoOcpp: don't compile built-in WS library
4848
extra_scripts = scripts/extra_script.py
4949
debug_flags =

src/MongooseOcppSocketClient.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ void MongooseOcppSocketClient::reconnect(const String &ws_url) {
206206
bool MongooseOcppSocketClient::sendTXT(String &out) {
207207
/*
208208
* Check if the EVSE is able to send the data at the moment. This fuzzy check can be useful to
209-
* to diagnose connection problems at upper layers. It gives no guarantee that packages were
210-
* actually sent successfully.
209+
* to diagnose connection problems at upper layers. It gives no guarantee that packages will
210+
* actually be sent successfully.
211211
*/
212212
if (!nc || !connection_established || !net_is_connected())
213213
return false;

src/app_config.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -312,28 +312,6 @@ config_save_mqtt(bool enable, int protocol, String server, uint16_t port, String
312312
config.commit();
313313
}
314314

315-
void
316-
config_save_ocpp(bool enable, String server, String ocpp_chargeBoxId, String ocpp_idTag, String tx_start_point, bool ocpp_suspend_evse, bool ocpp_energize_plug) {
317-
uint32_t newflags = flags & ~(CONFIG_SERVICE_OCPP | CONFIG_OCPP_ACCESS_SUSPEND | CONFIG_OCPP_ACCESS_ENERGIZE);
318-
if(enable) {
319-
newflags |= CONFIG_SERVICE_OCPP;
320-
}
321-
if(ocpp_suspend_evse) {
322-
newflags |= CONFIG_OCPP_ACCESS_SUSPEND;
323-
}
324-
if(ocpp_energize_plug) {
325-
newflags |= CONFIG_OCPP_ACCESS_ENERGIZE;
326-
}
327-
328-
config.set("ocpp_server", server);
329-
config.set("ocpp_chargeBoxId", ocpp_chargeBoxId);
330-
config.set("ocpp_idTag", ocpp_idTag);
331-
config.set("tx_start_point", tx_start_point);
332-
config.set("flags", newflags);
333-
config.commit();
334-
}
335-
336-
337315
void
338316
config_save_admin(String user, String pass) {
339317
config.set("www_username", user);

src/app_config.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ extern void config_save_emoncms(bool enable, String server, String node, String
145145
// -------------------------------------------------------------------
146146
extern void config_save_mqtt(bool enable, int protocol, String server, uint16_t port, String topic, String user, String pass, String solar, String grid_ie, bool reject_unauthorized);
147147

148-
// -------------------------------------------------------------------
149-
// Save the OCPP connection details
150-
// -------------------------------------------------------------------
151-
extern void config_save_ocpp(bool enable, String server, String ocpp_chargeBoxId, String ocpp_idTag, String tx_start_point, bool ocpp_suspend_evse, bool ocpp_energize_plug);
152-
153148
// -------------------------------------------------------------------
154149
// Save the admin/web interface details
155150
// -------------------------------------------------------------------

src/main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,6 @@ loop() {
219219
emoncms_publish(data);
220220
emoncms_updated = false;
221221
}
222-
223-
ocpp.poll();
224222
} // end WiFi connected
225223

226224
Profile_End(loop, 10);

src/ocpp.cpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,20 @@ void ArduinoOcppTask::loadEvseBehavior() {
175175

176176
unsigned long ArduinoOcppTask::loop(MicroTasks::WakeReason reason) {
177177

178-
if (!config_ocpp_enabled()) {
179-
return 5000;
180-
}
181-
182-
if (!arduinoOcppInitialized) {
183-
initializeArduinoOcpp();
184-
loadEvseBehavior();
178+
if (arduinoOcppInitialized) {
179+
if (config_ocpp_enabled()) {
180+
OCPP_loop();
181+
} else {
182+
//The OCPP function has been activated and then deactivated again.
185183

184+
ArduinoOcpp::ocppEngine_loop(); //There could be remaining operations in the OCPP-queue. I will add the OCPP_unitialize() soon as a better solution to this
185+
return 0;
186+
}
187+
} else {
188+
if (config_ocpp_enabled()) {
189+
initializeArduinoOcpp();
190+
loadEvseBehavior();
191+
}
186192
return 50;
187193
}
188194

@@ -201,17 +207,7 @@ unsigned long ArduinoOcppTask::loop(MicroTasks::WakeReason reason) {
201207
onVehicleDisconnect();
202208
}
203209

204-
return 50;
205-
}
206-
207-
void ArduinoOcppTask::poll() {
208-
if (arduinoOcppInitialized) {
209-
if (config_ocpp_enabled()) {
210-
OCPP_loop();
211-
} else {
212-
ArduinoOcpp::ocppEngine_loop(); //better continue looping. Leftover pending messages could interfere with the networking stack
213-
}
214-
}
210+
return 0;
215211
}
216212

217213
void ArduinoOcppTask::updateEvseClaim() {
@@ -281,14 +277,24 @@ void ArduinoOcppTask::updateEvseClaim() {
281277
}
282278

283279
String ArduinoOcppTask::getCentralSystemUrl() {
284-
ocpp_server.trim();
285280
String url = ocpp_server;
281+
url.trim();
282+
if (url.isEmpty()) {
283+
return url; //return empty String
284+
}
286285
if (!url.endsWith("/")) {
287286
url += '/';
288287
}
289-
ocpp_chargeBoxId.trim();
290-
url += ocpp_chargeBoxId;
291-
return url;
288+
String chargeBoxId = ocpp_chargeBoxId;
289+
chargeBoxId.trim();
290+
url += chargeBoxId;
291+
292+
if (MongooseOcppSocketClient::isValidUrl(url.c_str())) {
293+
return url;
294+
} else {
295+
DBUGLN(F("[ArduinoOcppTask] OCPP server URL or chargeBoxId invalid"));
296+
return String("");
297+
}
292298
}
293299

294300
void ArduinoOcppTask::notifyConfigChanged() {

src/ocpp.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ class ArduinoOcppTask: public MicroTasks::Task {
3333
std::function<void()> onVehicleConnect = [] () {};
3434
std::function<void()> onVehicleDisconnect = [] () {};
3535

36-
/*
37-
* OpenEVSE connector claiming rules
38-
*/
39-
std::function<void(EvseState&, EvseProperties&)> inferClaimTransactionActive = [] (EvseState&, EvseProperties&) {}; //Transaction engaged and accepted by the CS
40-
std::function<void(EvseState&, EvseProperties&)> inferClaimTransactionActiveOffline = [] (EvseState&, EvseProperties&) {}; //Transaction request pending. EVSE may choose to start charging
41-
std::function<void(EvseState&, EvseProperties&)> inferClaimTransactionInactive = [] (EvseState&, EvseProperties&) {}; //No transaction
42-
std::function<void(EvseState&, EvseProperties&, float charging_limit)> inferClaimSmartCharging = [] (EvseState&, EvseProperties&, float) {};
43-
4436
void initializeArduinoOcpp();
4537
bool arduinoOcppInitialized = false;
4638
void loadEvseBehavior();
@@ -66,8 +58,6 @@ class ArduinoOcppTask: public MicroTasks::Task {
6658
~ArduinoOcppTask();
6759

6860
void begin(EvseManager &evse, LcdTask &lcd);
69-
70-
void poll();
7161

7262
void updateEvseClaim();
7363

src/web_server.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -361,47 +361,6 @@ handleSaveMqtt(MongooseHttpServerRequest *request) {
361361
mqtt_restart();
362362
}
363363

364-
// -------------------------------------------------------------------
365-
// Save OCPP V1.6 Config
366-
// url: /saveocpp
367-
// -------------------------------------------------------------------
368-
void
369-
handleSaveOcpp(MongooseHttpServerRequest *request) {
370-
MongooseHttpServerResponseStream *response;
371-
if(false == requestPreProcess(request, response, CONTENT_TYPE_TEXT)) {
372-
return;
373-
}
374-
375-
String url = request->getParam("ocpp_server");
376-
377-
if (!MongooseOcppSocketClient::isValidUrl(url.c_str())) {
378-
response->setCode(400);
379-
response->print("invalid URL");
380-
request->send(response);
381-
return;
382-
}
383-
384-
config_save_ocpp(isPositive(request->getParam("ocpp_enabled")),
385-
url,
386-
request->getParam("ocpp_chargeBoxId"),
387-
request->getParam("ocpp_idTag"),
388-
request->getParam("tx_start_point"),
389-
isPositive(request->getParam("ocpp_suspend_evse")),
390-
isPositive(request->getParam("ocpp_energize_plug")));
391-
392-
char tmpStr[200];
393-
snprintf(tmpStr, sizeof(tmpStr), "Saved: %s %s %s %s %d %d %d",
394-
ocpp_server.c_str(), ocpp_chargeBoxId.c_str(), ocpp_idTag.c_str(), tx_start_point.c_str(),
395-
(int) config_ocpp_enabled(), (int) config_ocpp_access_can_energize, (int) config_ocpp_access_can_suspend());
396-
DBUGLN(tmpStr);
397-
398-
response->setCode(200);
399-
response->print(tmpStr);
400-
request->send(response);
401-
402-
ArduinoOcppTask::notifyConfigChanged();
403-
}
404-
405364
// -------------------------------------------------------------------
406365
// Change divert mode (solar PV divert mode) e.g 1:Normal (default), 2:Eco
407366
// url: /divertmode
@@ -1275,7 +1234,6 @@ web_server_setup() {
12751234
server.on("/savenetwork$", handleSaveNetwork);
12761235
server.on("/saveemoncms$", handleSaveEmoncms);
12771236
server.on("/savemqtt$", handleSaveMqtt);
1278-
server.on("/saveocpp$", handleSaveOcpp);
12791237
server.on("/saveadmin$", handleSaveAdmin);
12801238
server.on("/teslaveh$", handleTeslaVeh);
12811239
server.on("/saveadvanced$", handleSaveAdvanced);

0 commit comments

Comments
 (0)