Skip to content

Commit ef410e1

Browse files
committed
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
1 parent d4d2795 commit ef410e1

File tree

10 files changed

+42
-16
lines changed

10 files changed

+42
-16
lines changed

components/esp_rainmaker/include/esp_rmaker_core.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,20 @@ esp_err_t esp_rmaker_system_service_enable(esp_rmaker_system_serv_config_t *conf
917917
*/
918918
bool esp_rmaker_local_ctrl_service_started(void);
919919

920+
/**
921+
* Enable Default RainMaker OTA Firmware Upgrade
922+
*
923+
* This enables the default recommended RainMaker OTA Firmware Upgrade, which is
924+
* "Using the Topics", which allows performing OTA from Dashboard.
925+
* This OTA can be triggered by Admin Users only.
926+
* On Public RainMaker deployment, for nodes using "Self Claiming", since there
927+
* is no associated admin user, the Primary user will automatically become the admin
928+
* and can perform OTA from dashboard.
929+
*
930+
* @return ESP_OK on success
931+
* @return error on failure
932+
*/
933+
esp_err_t esp_rmaker_ota_enable_default(void);
920934
#ifdef __cplusplus
921935
}
922936
#endif

components/esp_rainmaker/src/core/esp_rmaker_node_config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static esp_err_t esp_rmaker_report_info(json_gen_str_t *jptr)
3838
}
3939
json_gen_obj_set_string(jptr, "model", info->model);
4040
const esp_app_desc_t *app_desc = esp_ota_get_app_description();
41-
json_gen_obj_set_string(jptr, "project_name", app_desc->project_name);
41+
json_gen_obj_set_string(jptr, "project_name", (char *)app_desc->project_name);
4242
json_gen_obj_set_string(jptr, "platform", CONFIG_IDF_TARGET);
4343
json_gen_pop_object(jptr);
4444
return ESP_OK;

components/esp_rainmaker/src/ota/esp_rmaker_ota.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,16 @@ esp_err_t esp_rmaker_ota_default_cb(esp_rmaker_ota_handle_t ota_handle, esp_rmak
284284
return ESP_FAIL;
285285
}
286286

287+
static const esp_rmaker_ota_config_t ota_default_config = {
288+
.server_cert = esp_rmaker_ota_def_cert,
289+
};
287290
/* Enable the ESP RainMaker specific OTA */
288291
esp_err_t esp_rmaker_ota_enable(esp_rmaker_ota_config_t *ota_config, esp_rmaker_ota_type_t type)
289292
{
290-
if (!ota_config || ((type != OTA_USING_PARAMS) && (type != OTA_USING_TOPICS))) {
293+
if (ota_config == NULL) {
294+
ota_config = (esp_rmaker_ota_config_t *)&ota_default_config;
295+
}
296+
if ((type != OTA_USING_PARAMS) && (type != OTA_USING_TOPICS)) {
291297
ESP_LOGE(TAG,"Invalid arguments for esp_rmaker_ota_enable()");
292298
return ESP_ERR_INVALID_ARG;
293299
}
@@ -343,3 +349,8 @@ esp_err_t esp_rmaker_ota_enable(esp_rmaker_ota_config_t *ota_config, esp_rmaker_
343349
}
344350
return err;
345351
}
352+
353+
esp_err_t esp_rmaker_ota_enable_default(void)
354+
{
355+
return esp_rmaker_ota_enable(NULL, OTA_USING_TOPICS);
356+
}

examples/fan/main/app_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ void app_main()
9191
esp_rmaker_device_add_param(fan_device, esp_rmaker_speed_param_create(ESP_RMAKER_DEF_SPEED_NAME, DEFAULT_SPEED));
9292
esp_rmaker_node_add_device(node, fan_device);
9393

94+
/* Enable OTA */
95+
esp_rmaker_ota_enable_default();
96+
9497
/* Enable timezone service which will be require for setting appropriate timezone
9598
* from the phone apps for scheduling to work correctly.
9699
* For more information on the various ways of setting timezone, please check

examples/gpio/main/app_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ void app_main()
8686

8787
esp_rmaker_node_add_device(node, gpio_device);
8888

89+
/* Enable OTA */
90+
esp_rmaker_ota_enable_default();
91+
8992
/* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */
9093
app_insights_enable();
9194

examples/homekit_switch/main/app_main.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,7 @@ void app_main()
182182
esp_rmaker_node_add_device(node, switch_device);
183183

184184
/* Enable OTA */
185-
esp_rmaker_ota_config_t ota_config = {
186-
.server_cert = ESP_RMAKER_OTA_DEFAULT_SERVER_CERT,
187-
};
188-
esp_rmaker_ota_enable(&ota_config, OTA_USING_PARAMS);
185+
esp_rmaker_ota_enable_default();
189186

190187
/* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */
191188
app_insights_enable();

examples/led_light/main/app_main.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <esp_rmaker_core.h>
1717
#include <esp_rmaker_standard_params.h>
1818
#include <esp_rmaker_standard_devices.h>
19-
#include <esp_rmaker_ota.h>
2019
#include <esp_rmaker_schedule.h>
2120
#include <esp_rmaker_scenes.h>
2221

@@ -105,10 +104,7 @@ void app_main()
105104
esp_rmaker_node_add_device(node, light_device);
106105

107106
/* Enable OTA */
108-
esp_rmaker_ota_config_t ota_config = {
109-
.server_cert = ESP_RMAKER_OTA_DEFAULT_SERVER_CERT,
110-
};
111-
esp_rmaker_ota_enable(&ota_config, OTA_USING_PARAMS);
107+
esp_rmaker_ota_enable_default();
112108

113109
/* Enable timezone service which will be require for setting appropriate timezone
114110
* from the phone apps for scheduling to work correctly.

examples/multi_device/main/app_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ void app_main()
120120
temp_sensor_device = esp_rmaker_temp_sensor_device_create("Temperature Sensor", NULL, app_get_current_temperature());
121121
esp_rmaker_node_add_device(node, temp_sensor_device);
122122

123+
/* Enable OTA */
124+
esp_rmaker_ota_enable_default();
125+
123126
/* Enable timezone service which will be require for setting appropriate timezone
124127
* from the phone apps for scheduling to work correctly.
125128
* For more information on the various ways of setting timezone, please check

examples/switch/main/app_main.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <esp_rmaker_standard_types.h>
1919
#include <esp_rmaker_standard_params.h>
2020
#include <esp_rmaker_standard_devices.h>
21-
#include <esp_rmaker_ota.h>
2221
#include <esp_rmaker_schedule.h>
2322
#include <esp_rmaker_scenes.h>
2423
#include <esp_rmaker_console.h>
@@ -184,10 +183,7 @@ void app_main()
184183
esp_rmaker_node_add_device(node, switch_device);
185184

186185
/* Enable OTA */
187-
esp_rmaker_ota_config_t ota_config = {
188-
.server_cert = ESP_RMAKER_OTA_DEFAULT_SERVER_CERT,
189-
};
190-
esp_rmaker_ota_enable(&ota_config, OTA_USING_PARAMS);
186+
esp_rmaker_ota_enable_default();
191187

192188
/* Enable timezone service which will be require for setting appropriate timezone
193189
* from the phone apps for scheduling to work correctly.

examples/temperature_sensor/main/app_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ void app_main()
6262
temp_sensor_device = esp_rmaker_temp_sensor_device_create("Temperature Sensor", NULL, app_get_current_temperature());
6363
esp_rmaker_node_add_device(node, temp_sensor_device);
6464

65+
/* Enable OTA */
66+
esp_rmaker_ota_enable_default();
67+
6568
/* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */
6669
app_insights_enable();
6770

0 commit comments

Comments
 (0)