Skip to content

Commit b61dc04

Browse files
committed
Merge branch 'task/def_param_name_changes' into 'master'
esp_rmaker_standard_types: Start default names of all standard params with capital letter See merge request app-frameworks/esp-rainmaker!171
2 parents e8532e4 + 367b48c commit b61dc04

File tree

12 files changed

+67
-40
lines changed

12 files changed

+67
-40
lines changed

CHANGES.md

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

3+
## 29-Sep-2020 (esp_rmaker_standard_types: Start default names of all standard params with capital letter)
4+
5+
Default parameter names like name, power, etc. have been changed to Name, Power, etc. respectively, so that they look better in the phone app UIs.
6+
7+
With this change, any user configured device name (the name set from phone apps), or any other persistent parameter for which a
8+
default name was used (Eg. power) will be affected, as the values will no more be found in the NVS storage.
9+
Please edit your application code accordingly if you want to stick with the old names.
10+
11+
Eg. If you were using the standard lightbulb device API which internally creates power and name parameters
12+
```
13+
light_device = esp_rmaker_lightbulb_device_create("Light", NULL, DEFAULT_POWER);
14+
```
15+
16+
Please change to below, if you want to stick with old parameter names "name" and "power".
17+
18+
```
19+
light_device = esp_rmaker_device_create("Light", ESP_RMAKER_DEVICE_LIGHTBULB, NULL);
20+
esp_rmaker_device_add_param(light_device, esp_rmaker_name_param_create("name", "Light"));
21+
esp_rmaker_param_t *power_param = esp_rmaker_power_param_create("power", DEFAULT_POWER);
22+
esp_rmaker_device_add_param(light_device, power_param);
23+
esp_rmaker_device_assign_primary_param(light_device, power_param);
24+
```
25+
326
## 5-Aug-2020 (wifi_provisioning: Use a random pop instead of creating it from MAC address)
427

528
Till date, the last 4 bytes of the MAC address were being used to generate the 8 character Proof of Possession (PoP) PIN for Wi-Fi provisioning. This is not secure enough because MAC address is a public information and can also be sniffed easily by devices in vicinity. A minor risk in this is that somebody else in the vicinity can provision your device, but a major risk is a man in the middle attack, wherein someone in vicinity can read the data being exchanged between a phone and the device and get the Wi-Fi credentials.

components/esp_rainmaker/include/esp_rmaker_standard_params.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,22 @@ extern "C"
2828
* @note These names are not mandatory. You can use the ESP RainMaker Core APIs
2929
* to create your own parameters with custom names, if required.
3030
*/
31-
#define ESP_RMAKER_DEF_NAME_PARAM "name"
32-
#define ESP_RMAKER_DEF_POWER_NAME "power"
33-
#define ESP_RMAKER_DEF_BRIGHTNESS_NAME "brightness"
34-
#define ESP_RMAKER_DEF_HUE_NAME "hue"
35-
#define ESP_RMAKER_DEF_SATURATION_NAME "saturation"
36-
#define ESP_RMAKER_DEF_INTENSITY_NAME "intensity"
37-
#define ESP_RMAKER_DEF_CCT_NAME "cct"
38-
#define ESP_RMAKER_DEF_DIRECTION_NAME "direction"
39-
#define ESP_RMAKER_DEF_SPEED_NAME "speed"
40-
#define ESP_RMAKER_DEF_TEMPERATURE_NAME "temperature"
41-
#define ESP_RMAKER_DEF_OTA_STATUS_NAME "status"
42-
#define ESP_RMAKER_DEF_OTA_INFO_NAME "info"
43-
#define ESP_RMAKER_DEF_OTA_URL_NAME "url"
44-
#define ESP_RMAKER_DEF_TIMEZONE_NAME "tz"
45-
#define ESP_RMAKER_DEF_TIMEZONE_POSIX_NAME "tz_posix"
31+
32+
#define ESP_RMAKER_DEF_NAME_PARAM "Name"
33+
#define ESP_RMAKER_DEF_POWER_NAME "Power"
34+
#define ESP_RMAKER_DEF_BRIGHTNESS_NAME "Brightness"
35+
#define ESP_RMAKER_DEF_HUE_NAME "Hue"
36+
#define ESP_RMAKER_DEF_SATURATION_NAME "Saturation"
37+
#define ESP_RMAKER_DEF_INTENSITY_NAME "Intensity"
38+
#define ESP_RMAKER_DEF_CCT_NAME "CCT"
39+
#define ESP_RMAKER_DEF_DIRECTION_NAME "Direction"
40+
#define ESP_RMAKER_DEF_SPEED_NAME "Speed"
41+
#define ESP_RMAKER_DEF_TEMPERATURE_NAME "Temperature"
42+
#define ESP_RMAKER_DEF_OTA_STATUS_NAME "Status"
43+
#define ESP_RMAKER_DEF_OTA_INFO_NAME "Info"
44+
#define ESP_RMAKER_DEF_OTA_URL_NAME "URL"
45+
#define ESP_RMAKER_DEF_TIMEZONE_NAME "TZ"
46+
#define ESP_RMAKER_DEF_TIMEZONE_POSIX_NAME "TZ-POSIX"
4647

4748
/**
4849
* Create standard name param

components/esp_rainmaker/src/core/esp_rmaker_time_sync.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static const char *TAG = "esp_rmaker_time_sync";
2525

2626
#define ESP_RMAKER_NVS_PART_NAME "nvs"
2727

28-
#define ESP_RMAKER_TIME_SERV_NAME "time"
28+
#define ESP_RMAKER_TIME_SERV_NAME "Time"
2929
#define ESP_RMAKER_NVS_TIME_NAMESPACE "rmaker_time"
3030
#define ESP_RMAKER_TZ_POSIX_NVS_NAME "tz_posix"
3131
#define ESP_RMAKER_TZ_NVS_NAME "tz"

components/esp_rainmaker/src/ota/esp_rmaker_ota_using_params.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
static const char *TAG = "esp_rmaker_ota_using_params";
2929

30-
#define ESP_RMAKER_OTA_SERV_NAME "ota"
30+
#define ESP_RMAKER_OTA_SERV_NAME "OTA"
3131

3232
void esp_rmaker_ota_finish_using_params(esp_rmaker_ota_t *ota)
3333
{

examples/fan/main/app_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_pa
3535
ESP_LOGI(TAG, "Received value = %s for %s - %s",
3636
val.val.b? "true" : "false", device_name, param_name);
3737
app_fan_set_power(val.val.b);
38-
} else if (strcmp(param_name, "speed") == 0) {
38+
} else if (strcmp(param_name, ESP_RMAKER_DEF_SPEED_NAME) == 0) {
3939
ESP_LOGI(TAG, "Received value = %d for %s - %s",
4040
val.val.i, device_name, param_name);
4141
app_fan_set_speed(val.val.i);
@@ -82,7 +82,7 @@ void app_main()
8282
/* Create a device and add the relevant parameters to it */
8383
fan_device = esp_rmaker_fan_device_create("Fan", NULL, DEFAULT_POWER);
8484
esp_rmaker_device_add_cb(fan_device, write_cb, NULL);
85-
esp_rmaker_device_add_param(fan_device, esp_rmaker_speed_param_create("speed", DEFAULT_SPEED));
85+
esp_rmaker_device_add_param(fan_device, esp_rmaker_speed_param_create(ESP_RMAKER_DEF_SPEED_NAME, DEFAULT_SPEED));
8686
esp_rmaker_node_add_device(node, fan_device);
8787

8888
/* Start the ESP RainMaker Agent */

examples/homekit_switch/main/app_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void push_btn_cb(void *arg)
5252
bool new_state = !g_power_state;
5353
app_driver_set_state(new_state);
5454
esp_rmaker_param_update_and_report(
55-
esp_rmaker_device_get_param_by_name(switch_device, "power"),
55+
esp_rmaker_device_get_param_by_name(switch_device, ESP_RMAKER_DEF_POWER_NAME),
5656
esp_rmaker_bool(new_state));
5757
app_homekit_update_state(new_state);
5858
}

examples/homekit_switch/main/app_homekit.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <esp_log.h>
1414

1515
#include <esp_rmaker_core.h>
16+
#include <esp_rmaker_standard_params.h>
17+
1618
#include <hap.h>
1719
#include <hap_apple_servs.h>
1820
#include <hap_apple_chars.h>
@@ -91,7 +93,7 @@ static int switch_write(hap_write_data_t write_data[], int count,
9193
hap_char_update_val(write->hc, &(write->val));
9294
/* Report to RainMaker */
9395
esp_rmaker_param_update_and_report(
94-
esp_rmaker_device_get_param_by_name(switch_device, "power"),
96+
esp_rmaker_device_get_param_by_name(switch_device, ESP_RMAKER_DEF_POWER_NAME),
9597
esp_rmaker_bool(write->val.b));
9698

9799
*(write->status) = HAP_STATUS_SUCCESS;

examples/homekit_switch/main/app_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ esp_rmaker_device_t *switch_device;
3131
static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param,
3232
const esp_rmaker_param_val_t val, void *priv_data, esp_rmaker_write_ctx_t *ctx)
3333
{
34-
if (strcmp(esp_rmaker_param_get_name(param), "power") == 0) {
34+
if (strcmp(esp_rmaker_param_get_name(param), ESP_RMAKER_DEF_POWER_NAME) == 0) {
3535
ESP_LOGI(TAG, "Received value = %s for %s - %s",
3636
val.val.b? "true" : "false", esp_rmaker_device_get_name(device),
3737
esp_rmaker_param_get_name(param));
@@ -128,12 +128,12 @@ void app_main()
128128
* user friendly custom name from the phone apps. All devices are recommended to have this
129129
* parameter.
130130
*/
131-
esp_rmaker_device_add_param(switch_device, esp_rmaker_name_param_create("name", "Switch"));
131+
esp_rmaker_device_add_param(switch_device, esp_rmaker_name_param_create(ESP_RMAKER_DEF_NAME_PARAM, "Switch"));
132132

133133
/* Add the standard power parameter (type: esp.param.power), which adds a boolean param
134134
* with a toggle switch ui-type.
135135
*/
136-
esp_rmaker_param_t *power_param = esp_rmaker_power_param_create("power", DEFAULT_POWER);
136+
esp_rmaker_param_t *power_param = esp_rmaker_power_param_create(ESP_RMAKER_DEF_POWER_NAME, DEFAULT_POWER);
137137
esp_rmaker_device_add_param(switch_device, power_param);
138138

139139
/* Assign the power parameter as the primary, so that it can be controlled from the

examples/led_light/main/app_main.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_pa
3838
ESP_LOGI(TAG, "Received value = %s for %s - %s",
3939
val.val.b? "true" : "false", device_name, param_name);
4040
app_light_set_power(val.val.b);
41-
} else if (strcmp(param_name, "brightness") == 0) {
41+
} else if (strcmp(param_name, ESP_RMAKER_DEF_BRIGHTNESS_NAME) == 0) {
4242
ESP_LOGI(TAG, "Received value = %d for %s - %s",
4343
val.val.i, device_name, param_name);
4444
app_light_set_brightness(val.val.i);
45-
} else if (strcmp(param_name, "hue") == 0) {
45+
} else if (strcmp(param_name, ESP_RMAKER_DEF_HUE_NAME) == 0) {
4646
ESP_LOGI(TAG, "Received value = %d for %s - %s",
4747
val.val.i, device_name, param_name);
4848
app_light_set_hue(val.val.i);
49-
} else if (strcmp(param_name, "saturation") == 0) {
49+
} else if (strcmp(param_name, ESP_RMAKER_DEF_SATURATION_NAME) == 0) {
5050
ESP_LOGI(TAG, "Received value = %d for %s - %s",
5151
val.val.i, device_name, param_name);
5252
app_light_set_saturation(val.val.i);
@@ -94,9 +94,9 @@ void app_main()
9494
light_device = esp_rmaker_lightbulb_device_create("Light", NULL, DEFAULT_POWER);
9595
esp_rmaker_device_add_cb(light_device, write_cb, NULL);
9696

97-
esp_rmaker_device_add_param(light_device, esp_rmaker_brightness_param_create("brightness", DEFAULT_BRIGHTNESS));
98-
esp_rmaker_device_add_param(light_device, esp_rmaker_hue_param_create("hue", DEFAULT_HUE));
99-
esp_rmaker_device_add_param(light_device, esp_rmaker_saturation_param_create("saturation", DEFAULT_SATURATION));
97+
esp_rmaker_device_add_param(light_device, esp_rmaker_brightness_param_create(ESP_RMAKER_DEF_BRIGHTNESS_NAME, DEFAULT_BRIGHTNESS));
98+
esp_rmaker_device_add_param(light_device, esp_rmaker_hue_param_create(ESP_RMAKER_DEF_HUE_NAME, DEFAULT_HUE));
99+
esp_rmaker_device_add_param(light_device, esp_rmaker_saturation_param_create(ESP_RMAKER_DEF_SATURATION_NAME, DEFAULT_SATURATION));
100100

101101
esp_rmaker_node_add_device(node, light_device);
102102

examples/multi_device/main/app_main.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_pa
4040
if (strcmp(device_name, "Switch") == 0) {
4141
app_driver_set_state(val.val.b);
4242
}
43-
} else if (strcmp(param_name, "brightness") == 0) {
43+
} else if (strcmp(param_name, ESP_RMAKER_DEF_BRIGHTNESS_NAME) == 0) {
4444
ESP_LOGI(TAG, "Received value = %d for %s - %s",
4545
val.val.i, device_name, param_name);
46-
} else if (strcmp(param_name, "speed") == 0) {
46+
} else if (strcmp(param_name, ESP_RMAKER_DEF_SPEED_NAME) == 0) {
4747
ESP_LOGI(TAG, "Received value = %d for %s - %s",
4848
val.val.i, device_name, param_name);
4949
} else {
@@ -96,17 +96,18 @@ void app_main()
9696
light_device = esp_rmaker_lightbulb_device_create("Light", NULL, DEFAULT_LIGHT_POWER);
9797
esp_rmaker_device_add_cb(light_device, write_cb, NULL);
9898

99-
esp_rmaker_device_add_param(light_device, esp_rmaker_brightness_param_create("brightness", DEFAULT_LIGHT_BRIGHTNESS));
99+
esp_rmaker_device_add_param(light_device,
100+
esp_rmaker_brightness_param_create(ESP_RMAKER_DEF_BRIGHTNESS_NAME, DEFAULT_LIGHT_BRIGHTNESS));
100101

101-
esp_rmaker_device_add_attribute(light_device, "serial_number", "012345");
102-
esp_rmaker_device_add_attribute(light_device, "mac", "xx:yy:zz:aa:bb:cc");
102+
esp_rmaker_device_add_attribute(light_device, "Serial Number", "012345");
103+
esp_rmaker_device_add_attribute(light_device, "MAC", "xx:yy:zz:aa:bb:cc");
103104

104105
esp_rmaker_node_add_device(node, light_device);
105106

106107
/* Create a Fan device and add the relevant parameters to it */
107108
fan_device = esp_rmaker_fan_device_create("Fan", NULL, DEFAULT_FAN_POWER);
108109
esp_rmaker_device_add_cb(fan_device, write_cb, NULL);
109-
esp_rmaker_device_add_param(fan_device, esp_rmaker_speed_param_create("speed", DEFAULT_FAN_SPEED));
110+
esp_rmaker_device_add_param(fan_device, esp_rmaker_speed_param_create(ESP_RMAKER_DEF_SPEED_NAME, DEFAULT_FAN_SPEED));
110111
esp_rmaker_node_add_device(node, fan_device);
111112

112113
/* Create a Temperature Sensor device and add the relevant parameters to it */

examples/switch/main/app_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void push_btn_cb(void *arg)
5252
bool new_state = !g_power_state;
5353
app_driver_set_state(new_state);
5454
esp_rmaker_param_update_and_report(
55-
esp_rmaker_device_get_param_by_name(switch_device, "power"),
55+
esp_rmaker_device_get_param_by_name(switch_device, ESP_RMAKER_DEF_POWER_NAME),
5656
esp_rmaker_bool(new_state));
5757
}
5858

examples/switch/main/app_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ esp_rmaker_device_t *switch_device;
3232
static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param,
3333
const esp_rmaker_param_val_t val, void *priv_data, esp_rmaker_write_ctx_t *ctx)
3434
{
35-
if (strcmp(esp_rmaker_param_get_name(param), "power") == 0) {
35+
if (strcmp(esp_rmaker_param_get_name(param), ESP_RMAKER_DEF_POWER_NAME) == 0) {
3636
ESP_LOGI(TAG, "Received value = %s for %s - %s",
3737
val.val.b? "true" : "false", esp_rmaker_device_get_name(device),
3838
esp_rmaker_param_get_name(param));
@@ -128,12 +128,12 @@ void app_main()
128128
* user friendly custom name from the phone apps. All devices are recommended to have this
129129
* parameter.
130130
*/
131-
esp_rmaker_device_add_param(switch_device, esp_rmaker_name_param_create("name", "Switch"));
131+
esp_rmaker_device_add_param(switch_device, esp_rmaker_name_param_create(ESP_RMAKER_DEF_NAME_PARAM, "Switch"));
132132

133133
/* Add the standard power parameter (type: esp.param.power), which adds a boolean param
134134
* with a toggle switch ui-type.
135135
*/
136-
esp_rmaker_param_t *power_param = esp_rmaker_power_param_create("power", DEFAULT_POWER);
136+
esp_rmaker_param_t *power_param = esp_rmaker_power_param_create(ESP_RMAKER_DEF_POWER_NAME, DEFAULT_POWER);
137137
esp_rmaker_device_add_param(switch_device, power_param);
138138

139139
/* Assign the power parameter as the primary, so that it can be controlled from the

0 commit comments

Comments
 (0)