|
10 | 10 | #include <ArduinoOcpp.h> // Facade for ArduinoOcpp |
11 | 11 | #include <ArduinoOcpp/SimpleOcppOperationFactory.h> // define behavior for incoming req messages |
12 | 12 |
|
13 | | -#include <HTTPUpdate.h> |
14 | | -#include <MongooseHttpClient.h> //for HTTP update |
| 13 | +#include "http_update.h" |
15 | 14 |
|
16 | 15 | #include <ArduinoOcpp/Core/OcppEngine.h> |
17 | 16 |
|
@@ -70,11 +69,12 @@ void ArduinoOcppTask::initializeArduinoOcpp() { |
70 | 69 | DynamicJsonDocument *evseDetailsDoc = new DynamicJsonDocument(JSON_OBJECT_SIZE(6)); |
71 | 70 | JsonObject evseDetails = evseDetailsDoc->to<JsonObject>(); |
72 | 71 | evseDetails["chargePointModel"] = "Advanced Series"; |
73 | | - //evseDetails["chargePointSerialNumber"] = "TODO"; |
| 72 | + //evseDetails["chargePointSerialNumber"] = "TODO"; //see https://github.com/OpenEVSE/ESP32_WiFi_V4.x/issues/218 |
74 | 73 | evseDetails["chargePointVendor"] = "OpenEVSE"; |
75 | 74 | evseDetails["firmwareVersion"] = evse->getFirmwareVersion(); |
76 | 75 | //evseDetails["meterSerialNumber"] = "TODO"; |
77 | 76 | //evseDetails["meterType"] = "TODO"; |
| 77 | + //see https://github.com/OpenEVSE/ESP32_WiFi_V4.x/issues/219 |
78 | 78 |
|
79 | 79 | bootNotification(evseDetailsDoc, [this](JsonObject payload) { //ArduinoOcpp will delete evseDetailsDoc |
80 | 80 | LCD_DISPLAY("OCPP connected!"); |
@@ -242,6 +242,7 @@ void ArduinoOcppTask::loadEvseBehavior() { |
242 | 242 |
|
243 | 243 | setOnUnlockConnector([] () { |
244 | 244 | //TODO Send unlock command to peripherals. If successful, return true, otherwise false |
| 245 | + //see https://github.com/OpenEVSE/ESP32_WiFi_V4.x/issues/230 |
245 | 246 | return false; |
246 | 247 | }); |
247 | 248 |
|
@@ -526,14 +527,41 @@ void ArduinoOcppTask::initializeDiagnosticsService() { |
526 | 527 | } |
527 | 528 |
|
528 | 529 | void ArduinoOcppTask::initializeFwService() { |
529 | | - //TODO finish when HTTP FW download will be available in the OpenEVSE core |
530 | | - //ArduinoOcpp::FirmwareService *fwService = ArduinoOcpp::getFirmwareService(); |
531 | | - //if (fwService) { |
532 | | - // fwService->setOnInstall([this](String location) { |
533 | | - // ... |
534 | | - // return true; |
535 | | - // }); |
536 | | - //} |
| 530 | + ArduinoOcpp::FirmwareService *fwService = ArduinoOcpp::getFirmwareService(); |
| 531 | + if (fwService) { |
| 532 | + fwService->setBuildNumber(evse->getFirmwareVersion()); |
| 533 | + |
| 534 | + fwService->setInstallationStatusSampler([this] () { |
| 535 | + if (updateFailure) { |
| 536 | + return ArduinoOcpp::InstallationStatus::InstallationFailed; |
| 537 | + } else if (updateSuccess) { |
| 538 | + return ArduinoOcpp::InstallationStatus::Installed; |
| 539 | + } else { |
| 540 | + return ArduinoOcpp::InstallationStatus::NotInstalled; |
| 541 | + } |
| 542 | + }); |
| 543 | + |
| 544 | + fwService->setOnInstall([this](String &location) { |
| 545 | + |
| 546 | + DBUGLN(F("[ocpp] Starting installation routine")); |
| 547 | + |
| 548 | + //reset reported state |
| 549 | + updateFailure = false; |
| 550 | + updateSuccess = false; |
| 551 | + |
| 552 | + return http_update_from_url(location, [] (size_t complete, size_t total) { }, |
| 553 | + [this] (int status_code) { |
| 554 | + //onSuccess |
| 555 | + updateSuccess = true; |
| 556 | + |
| 557 | + resetTime = millis(); |
| 558 | + resetTriggered = true; |
| 559 | + }, [this] (int error_code) { |
| 560 | + //onFailure |
| 561 | + updateFailure = true; |
| 562 | + }); |
| 563 | + }); |
| 564 | + } |
537 | 565 | } |
538 | 566 |
|
539 | 567 | bool ArduinoOcppTask::operationIsAccepted(JsonObject payload) { |
|
0 commit comments