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
This commit is contained in:
Piyush Shah
2022-06-07 02:37:48 +08:00
12 changed files with 71 additions and 18 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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

View File

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

View File

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

View File

@@ -16,7 +16,6 @@
#include <esp_rmaker_core.h>
#include <esp_rmaker_standard_params.h>
#include <esp_rmaker_standard_devices.h>
#include <esp_rmaker_ota.h>
#include <esp_rmaker_schedule.h>
#include <esp_rmaker_scenes.h>
@@ -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.

View File

@@ -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

View File

@@ -18,7 +18,6 @@
#include <esp_rmaker_standard_types.h>
#include <esp_rmaker_standard_params.h>
#include <esp_rmaker_standard_devices.h>
#include <esp_rmaker_ota.h>
#include <esp_rmaker_schedule.h>
#include <esp_rmaker_scenes.h>
#include <esp_rmaker_console.h>
@@ -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.

View File

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