@@ -57,6 +57,7 @@ char RequiredEVCCID[32] = ""; // R
5757#include < MicroOcppMongooseClient.h>
5858#include < MicroOcpp/Core/Configuration.h>
5959#include < MicroOcpp/Core/Context.h>
60+ #include < MicroOcpp/Model/FirmwareManagement/FirmwareService.h>
6061#endif // ENABLE_OCPP
6162
6263#if SMARTEVSE_VERSION >= 40
@@ -2726,6 +2727,65 @@ void ocppInit() {
27262727
27272728 OcppUnlockConnectorOnEVSideDisconnect = MicroOcpp::declareConfiguration<bool >(" UnlockConnectorOnEVSideDisconnect" , true );
27282729
2730+ // OCPP Firmware Update: register download and install callbacks
2731+ auto fwService = getFirmwareService ();
2732+ if (fwService) {
2733+ static volatile int OcppFwStatus; // 0=idle, 1=downloading, 2=downloaded ok, -1=download failed
2734+ OcppFwStatus = 0 ;
2735+
2736+ fwService->setOnDownload ([] (const char *location) -> bool {
2737+ if (downloadProgress > 0 ) {
2738+ _LOG_A (" OCPP FW: rejected, another update is in progress\n " );
2739+ return false ;
2740+ }
2741+ OcppFwStatus = 1 ;
2742+ _LOG_A (" OCPP FW: download requested from %s\n " , location);
2743+
2744+ char *url = strdup (location);
2745+ if (!url) {
2746+ OcppFwStatus = -1 ;
2747+ return false ;
2748+ }
2749+
2750+ xTaskCreate ([] (void *param) {
2751+ char *fwUrl = (char *)param;
2752+ if (forceUpdate (fwUrl, true )) {
2753+ _LOG_A (" OCPP FW: download and flash successful\n " );
2754+ OcppFwStatus = 2 ;
2755+ } else {
2756+ _LOG_A (" OCPP FW: download or flash failed\n " );
2757+ OcppFwStatus = -1 ;
2758+ }
2759+ free (fwUrl);
2760+ vTaskDelete (NULL );
2761+ }, " OcppFwUpdate" , 4096 , url, 3 , NULL );
2762+
2763+ return true ;
2764+ });
2765+
2766+ fwService->setDownloadStatusInput ([] () -> MicroOcpp::DownloadStatus {
2767+ switch (OcppFwStatus) {
2768+ case 2 : return MicroOcpp::DownloadStatus::Downloaded;
2769+ case -1 : return MicroOcpp::DownloadStatus::DownloadFailed;
2770+ default : return MicroOcpp::DownloadStatus::NotDownloaded;
2771+ }
2772+ });
2773+
2774+ fwService->setOnInstall ([] (const char *location) -> bool {
2775+ _LOG_A (" OCPP FW: install phase, scheduling reboot\n " );
2776+ shouldReboot = true ;
2777+ return true ;
2778+ });
2779+
2780+ fwService->setInstallationStatusInput ([] () -> MicroOcpp::InstallationStatus {
2781+ if (shouldReboot) {
2782+ return MicroOcpp::InstallationStatus::Installed;
2783+ }
2784+ return MicroOcpp::InstallationStatus::NotInstalled;
2785+ });
2786+ }
2787+
2788+
27292789 endTransaction (nullptr , " PowerLoss" ); // If a transaction from previous power cycle is still running, abort it here
27302790}
27312791
0 commit comments