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();