From 7670899bbe4d19851e0e8f4af1b5ee5d1e42190f Mon Sep 17 00:00:00 2001 From: "sanket.wadekar" Date: Fri, 30 Sep 2022 15:20:45 +0530 Subject: [PATCH 1/2] Added OTA Event Handlers --- libraries/RainMaker/src/RMaker.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/libraries/RainMaker/src/RMaker.cpp b/libraries/RainMaker/src/RMaker.cpp index 5a3c65009a7..9cb00966df6 100644 --- a/libraries/RainMaker/src/RMaker.cpp +++ b/libraries/RainMaker/src/RMaker.cpp @@ -25,6 +25,33 @@ static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_ default: log_i("Unhandled RainMaker Event:"); } + } else if (event_base == RMAKER_OTA_EVENT) { + if(event_data == NULL){ + event_data = (void*)""; + } + switch(event_id) { + case RMAKER_OTA_EVENT_STARTING: + log_i("Starting OTA : %s", (char*)event_data); + break; + case RMAKER_OTA_EVENT_IN_PROGRESS: + log_i("OTA in progress : %s", (char*)event_data); + break; + case RMAKER_OTA_EVENT_SUCCESSFUL: + log_i("OTA Successful : %s", (char*)event_data); + break; + case RMAKER_OTA_EVENT_FAILED: + log_i("OTA Failed : %s", (char*)event_data); + break; + case RMAKER_OTA_EVENT_DELAYED: + log_i("OTA Delayed : %s", (char*)event_data); + break; + case RMAKER_OTA_EVENT_REJECTED: + log_i("OTA Rejected : %s", (char*)event_data); + break; + default: + log_i("Unhandled OTA Event"); + break; + } } } @@ -39,6 +66,7 @@ Node RMakerClass::initNode(const char *name, const char *type) Node node; esp_rmaker_node_t *rnode = NULL; esp_event_handler_register(RMAKER_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL); + esp_event_handler_register(RMAKER_OTA_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL); rnode = esp_rmaker_node_init(&rainmaker_cfg, name, type); if (!rnode){ log_e("Node init failed"); From 8e317c6d3d90f39ff5b01b8b8d9c7331c22ee3d5 Mon Sep 17 00:00:00 2001 From: "sanket.wadekar" Date: Fri, 30 Sep 2022 15:22:14 +0530 Subject: [PATCH 2/2] Overrided verifyRollbackLater Method --- libraries/RainMaker/src/RMaker.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/RainMaker/src/RMaker.cpp b/libraries/RainMaker/src/RMaker.cpp index 9cb00966df6..fc80e716424 100644 --- a/libraries/RainMaker/src/RMaker.cpp +++ b/libraries/RainMaker/src/RMaker.cpp @@ -6,6 +6,8 @@ bool wifiLowLevelInit(bool persistent); static esp_err_t err; +extern "C" bool verifyRollbackLater() { return true; } + static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { if (event_base == RMAKER_EVENT) { @@ -132,9 +134,11 @@ esp_err_t RMakerClass::enableTZService() esp_err_t RMakerClass::enableOTA(ota_type_t type, const char *cert) { - esp_rmaker_ota_config_t ota_config; - ota_config.server_cert = cert; - ota_config.ota_cb = NULL; + esp_rmaker_ota_config_t ota_config = { + .ota_cb = NULL, + .ota_diag = NULL, + .server_cert = cert, + }; err = esp_rmaker_ota_enable(&ota_config, type); if(err != ESP_OK) { log_e("OTA enable failed");