Skip to content

Commit e02cd57

Browse files
committed
Merge branch 'task/claim_ota' into 'master'
claim/ota: Make self claiming and OTA using Topics as defaults See merge request app-frameworks/esp-rainmaker!301
2 parents d4d2795 + b73f9e1 commit e02cd57

File tree

12 files changed

+71
-18
lines changed

12 files changed

+71
-18
lines changed

CHANGES.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
# Changes
22

3+
## 26-May-2022 (claiming and ota)
4+
5+
- claiming: Make self claiming as the default for esp32s3 and esp32c3
6+
- ota: Make "OTA using Topics" as default and provide a simplified API for that
7+
8+
Self claiming is much more convenient and fast since the node directly gets the
9+
credentials from the claiming service over HTTPS, instead of using the slower BLE based
10+
Assisted claiming, wherein the phone app acts as a proxy between the node and the
11+
claiming service. However, with self claiming, there was no concept of
12+
[Admin Role](https://rainmaker.espressif.com/docs/user-roles.html#admin-users) and so, it was
13+
not possible to access the node via the RainMaker or Insights dashboards. This was one
14+
reason why Assisted Claiming was kept as a default for esp32c3 and esp32s3 even though
15+
they support self claiming.
16+
17+
With recent changes in the Public RainMaker backend, the primary user (the user who performs the [user-node
18+
mapping](https://rainmaker.espressif.com/docs/user-node-mapping.html)) for a self claimed
19+
node is now made as the admin. This gives the primary user the access to the node for OTA and Insights.
20+
So, self claiming has now been made as the default for all chips (except esp32) and the OTA Using Topics
21+
has also been made as the default, since it is convenient and also the correct option for
22+
production devices. A simpler API `esp_rmaker_ota_enable_default()` as also been added in esp_rmaker_core.h.
23+
24+
Note: Nodes that are already claimed via Assisted/Host Claiming will not have any effect, even if the
25+
new firmware is enabled with self claiming. The self claiming will take effect only if the flash is
26+
erased. **This will result in a change of node_id, since mac address is the node_id for self claimed nodes.**
27+
If you want to contine using Assisted Claiming (probably because there is quite some data associated
28+
with the node_id), please set is explicitly in your sdkconfig.
29+
330
## 25-Jan-2022 (app_wifi: Minor feature additions to provisioning workflow)
431

532
Added a 30 minute timeout for Wi-Fi provisioning as a security measure. A device reboot will be

components/esp_rainmaker/Kconfig.projbuild

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ menu "ESP RainMaker Config"
22

33
choice ESP_RMAKER_CLAIM_TYPE
44
bool "Claiming Type"
5-
default ESP_RMAKER_SELF_CLAIM if IDF_TARGET_ESP32S2
6-
default ESP_RMAKER_ASSISTED_CLAIM if !IDF_TARGET_ESP32S2
5+
default ESP_RMAKER_SELF_CLAIM
6+
default ESP_RMAKER_ASSISTED_CLAIM if IDF_TARGET_ESP32
77
help
88
Claiming type to be used.
99

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)