From ef410e14b044aef62fa891bb79ac19f5a99ebb79 Mon Sep 17 00:00:00 2001 From: Piyush Shah Date: Thu, 26 May 2022 18:37:41 +0530 Subject: [PATCH 1/2] ota: Make "OTA using Topics" as default and provide a simplified API for that - OTA using topics is now enabled in all examples - esp_rmaker_ota_enable_default() is the simplified API that enables OTA using Topics with the default server certificates --- components/esp_rainmaker/include/esp_rmaker_core.h | 14 ++++++++++++++ .../src/core/esp_rmaker_node_config.c | 2 +- components/esp_rainmaker/src/ota/esp_rmaker_ota.c | 13 ++++++++++++- examples/fan/main/app_main.c | 3 +++ examples/gpio/main/app_main.c | 3 +++ examples/homekit_switch/main/app_main.c | 5 +---- examples/led_light/main/app_main.c | 6 +----- examples/multi_device/main/app_main.c | 3 +++ examples/switch/main/app_main.c | 6 +----- examples/temperature_sensor/main/app_main.c | 3 +++ 10 files changed, 42 insertions(+), 16 deletions(-) diff --git a/components/esp_rainmaker/include/esp_rmaker_core.h b/components/esp_rainmaker/include/esp_rmaker_core.h index ad83011..eb01e6d 100644 --- a/components/esp_rainmaker/include/esp_rmaker_core.h +++ b/components/esp_rainmaker/include/esp_rmaker_core.h @@ -917,6 +917,20 @@ esp_err_t esp_rmaker_system_service_enable(esp_rmaker_system_serv_config_t *conf */ bool esp_rmaker_local_ctrl_service_started(void); +/** + * Enable Default RainMaker OTA Firmware Upgrade + * + * This enables the default recommended RainMaker OTA Firmware Upgrade, which is + * "Using the Topics", which allows performing OTA from Dashboard. + * This OTA can be triggered by Admin Users only. + * On Public RainMaker deployment, for nodes using "Self Claiming", since there + * is no associated admin user, the Primary user will automatically become the admin + * and can perform OTA from dashboard. + * + * @return ESP_OK on success + * @return error on failure + */ +esp_err_t esp_rmaker_ota_enable_default(void); #ifdef __cplusplus } #endif diff --git a/components/esp_rainmaker/src/core/esp_rmaker_node_config.c b/components/esp_rainmaker/src/core/esp_rmaker_node_config.c index aa53ce3..47458d4 100644 --- a/components/esp_rainmaker/src/core/esp_rmaker_node_config.c +++ b/components/esp_rainmaker/src/core/esp_rmaker_node_config.c @@ -38,7 +38,7 @@ static esp_err_t esp_rmaker_report_info(json_gen_str_t *jptr) } json_gen_obj_set_string(jptr, "model", info->model); const esp_app_desc_t *app_desc = esp_ota_get_app_description(); - json_gen_obj_set_string(jptr, "project_name", app_desc->project_name); + json_gen_obj_set_string(jptr, "project_name", (char *)app_desc->project_name); json_gen_obj_set_string(jptr, "platform", CONFIG_IDF_TARGET); json_gen_pop_object(jptr); return ESP_OK; diff --git a/components/esp_rainmaker/src/ota/esp_rmaker_ota.c b/components/esp_rainmaker/src/ota/esp_rmaker_ota.c index 42734c4..6c293f7 100644 --- a/components/esp_rainmaker/src/ota/esp_rmaker_ota.c +++ b/components/esp_rainmaker/src/ota/esp_rmaker_ota.c @@ -284,10 +284,16 @@ ota_end: return ESP_FAIL; } +static const esp_rmaker_ota_config_t ota_default_config = { + .server_cert = esp_rmaker_ota_def_cert, +}; /* Enable the ESP RainMaker specific OTA */ esp_err_t esp_rmaker_ota_enable(esp_rmaker_ota_config_t *ota_config, esp_rmaker_ota_type_t type) { - if (!ota_config || ((type != OTA_USING_PARAMS) && (type != OTA_USING_TOPICS))) { + if (ota_config == NULL) { + ota_config = (esp_rmaker_ota_config_t *)&ota_default_config; + } + if ((type != OTA_USING_PARAMS) && (type != OTA_USING_TOPICS)) { ESP_LOGE(TAG,"Invalid arguments for esp_rmaker_ota_enable()"); return ESP_ERR_INVALID_ARG; } @@ -343,3 +349,8 @@ esp_err_t esp_rmaker_ota_enable(esp_rmaker_ota_config_t *ota_config, esp_rmaker_ } return err; } + +esp_err_t esp_rmaker_ota_enable_default(void) +{ + return esp_rmaker_ota_enable(NULL, OTA_USING_TOPICS); +} diff --git a/examples/fan/main/app_main.c b/examples/fan/main/app_main.c index 136b106..d57fbbe 100644 --- a/examples/fan/main/app_main.c +++ b/examples/fan/main/app_main.c @@ -91,6 +91,9 @@ void app_main() esp_rmaker_device_add_param(fan_device, esp_rmaker_speed_param_create(ESP_RMAKER_DEF_SPEED_NAME, DEFAULT_SPEED)); esp_rmaker_node_add_device(node, fan_device); + /* Enable OTA */ + esp_rmaker_ota_enable_default(); + /* Enable timezone service which will be require for setting appropriate timezone * from the phone apps for scheduling to work correctly. * For more information on the various ways of setting timezone, please check diff --git a/examples/gpio/main/app_main.c b/examples/gpio/main/app_main.c index ca512ac..c3cef0a 100644 --- a/examples/gpio/main/app_main.c +++ b/examples/gpio/main/app_main.c @@ -86,6 +86,9 @@ void app_main() esp_rmaker_node_add_device(node, gpio_device); + /* Enable OTA */ + esp_rmaker_ota_enable_default(); + /* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */ app_insights_enable(); diff --git a/examples/homekit_switch/main/app_main.c b/examples/homekit_switch/main/app_main.c index 519e40c..a6a64a5 100644 --- a/examples/homekit_switch/main/app_main.c +++ b/examples/homekit_switch/main/app_main.c @@ -182,10 +182,7 @@ void app_main() esp_rmaker_node_add_device(node, switch_device); /* Enable OTA */ - esp_rmaker_ota_config_t ota_config = { - .server_cert = ESP_RMAKER_OTA_DEFAULT_SERVER_CERT, - }; - esp_rmaker_ota_enable(&ota_config, OTA_USING_PARAMS); + esp_rmaker_ota_enable_default(); /* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */ app_insights_enable(); diff --git a/examples/led_light/main/app_main.c b/examples/led_light/main/app_main.c index e44451e..be08aac 100644 --- a/examples/led_light/main/app_main.c +++ b/examples/led_light/main/app_main.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -105,10 +104,7 @@ void app_main() esp_rmaker_node_add_device(node, light_device); /* Enable OTA */ - esp_rmaker_ota_config_t ota_config = { - .server_cert = ESP_RMAKER_OTA_DEFAULT_SERVER_CERT, - }; - esp_rmaker_ota_enable(&ota_config, OTA_USING_PARAMS); + esp_rmaker_ota_enable_default(); /* Enable timezone service which will be require for setting appropriate timezone * from the phone apps for scheduling to work correctly. diff --git a/examples/multi_device/main/app_main.c b/examples/multi_device/main/app_main.c index bc42426..99ae28e 100644 --- a/examples/multi_device/main/app_main.c +++ b/examples/multi_device/main/app_main.c @@ -120,6 +120,9 @@ void app_main() temp_sensor_device = esp_rmaker_temp_sensor_device_create("Temperature Sensor", NULL, app_get_current_temperature()); esp_rmaker_node_add_device(node, temp_sensor_device); + /* Enable OTA */ + esp_rmaker_ota_enable_default(); + /* Enable timezone service which will be require for setting appropriate timezone * from the phone apps for scheduling to work correctly. * For more information on the various ways of setting timezone, please check diff --git a/examples/switch/main/app_main.c b/examples/switch/main/app_main.c index 2c9886b..4db7f56 100644 --- a/examples/switch/main/app_main.c +++ b/examples/switch/main/app_main.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -184,10 +183,7 @@ void app_main() esp_rmaker_node_add_device(node, switch_device); /* Enable OTA */ - esp_rmaker_ota_config_t ota_config = { - .server_cert = ESP_RMAKER_OTA_DEFAULT_SERVER_CERT, - }; - esp_rmaker_ota_enable(&ota_config, OTA_USING_PARAMS); + esp_rmaker_ota_enable_default(); /* Enable timezone service which will be require for setting appropriate timezone * from the phone apps for scheduling to work correctly. diff --git a/examples/temperature_sensor/main/app_main.c b/examples/temperature_sensor/main/app_main.c index a7990c8..5ade3f6 100644 --- a/examples/temperature_sensor/main/app_main.c +++ b/examples/temperature_sensor/main/app_main.c @@ -62,6 +62,9 @@ void app_main() temp_sensor_device = esp_rmaker_temp_sensor_device_create("Temperature Sensor", NULL, app_get_current_temperature()); esp_rmaker_node_add_device(node, temp_sensor_device); + /* Enable OTA */ + esp_rmaker_ota_enable_default(); + /* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */ app_insights_enable(); From b73f9e1e636890570dabd563014f2980ccccbc12 Mon Sep 17 00:00:00 2001 From: Piyush Shah Date: Thu, 26 May 2022 23:25:15 +0530 Subject: [PATCH 2/2] claiming: Make self claiming as the default for esp32s3 and esp32c3 It was already the default for esp32s2. So, only esp32 will have assisted claiming as default. This change was made because RainMaker now supports admin roles even for Self Claimed nodes. Please check CHANGES.md for details --- CHANGES.md | 27 ++++++++++++++++++++++ components/esp_rainmaker/Kconfig.projbuild | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 00bd211..6c95677 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,32 @@ # Changes +## 26-May-2022 (claiming and ota) + +- claiming: Make self claiming as the default for esp32s3 and esp32c3 +- ota: Make "OTA using Topics" as default and provide a simplified API for that + +Self claiming is much more convenient and fast since the node directly gets the +credentials from the claiming service over HTTPS, instead of using the slower BLE based +Assisted claiming, wherein the phone app acts as a proxy between the node and the +claiming service. However, with self claiming, there was no concept of +[Admin Role](https://rainmaker.espressif.com/docs/user-roles.html#admin-users) and so, it was +not possible to access the node via the RainMaker or Insights dashboards. This was one +reason why Assisted Claiming was kept as a default for esp32c3 and esp32s3 even though +they support self claiming. + +With recent changes in the Public RainMaker backend, the primary user (the user who performs the [user-node +mapping](https://rainmaker.espressif.com/docs/user-node-mapping.html)) for a self claimed +node is now made as the admin. This gives the primary user the access to the node for OTA and Insights. +So, self claiming has now been made as the default for all chips (except esp32) and the OTA Using Topics +has also been made as the default, since it is convenient and also the correct option for +production devices. A simpler API `esp_rmaker_ota_enable_default()` as also been added in esp_rmaker_core.h. + +Note: Nodes that are already claimed via Assisted/Host Claiming will not have any effect, even if the +new firmware is enabled with self claiming. The self claiming will take effect only if the flash is +erased. **This will result in a change of node_id, since mac address is the node_id for self claimed nodes.** +If you want to contine using Assisted Claiming (probably because there is quite some data associated +with the node_id), please set is explicitly in your sdkconfig. + ## 25-Jan-2022 (app_wifi: Minor feature additions to provisioning workflow) Added a 30 minute timeout for Wi-Fi provisioning as a security measure. A device reboot will be diff --git a/components/esp_rainmaker/Kconfig.projbuild b/components/esp_rainmaker/Kconfig.projbuild index cb5a52b..1bd69c2 100644 --- a/components/esp_rainmaker/Kconfig.projbuild +++ b/components/esp_rainmaker/Kconfig.projbuild @@ -2,8 +2,8 @@ menu "ESP RainMaker Config" choice ESP_RMAKER_CLAIM_TYPE bool "Claiming Type" - default ESP_RMAKER_SELF_CLAIM if IDF_TARGET_ESP32S2 - default ESP_RMAKER_ASSISTED_CLAIM if !IDF_TARGET_ESP32S2 + default ESP_RMAKER_SELF_CLAIM + default ESP_RMAKER_ASSISTED_CLAIM if IDF_TARGET_ESP32 help Claiming type to be used.