From cfc2e10a1cd4e3194cefe84267f7f960ef7ddd46 Mon Sep 17 00:00:00 2001 From: shripad621git Date: Wed, 1 Mar 2023 13:08:03 +0530 Subject: [PATCH] Added fixed labels using nvs in generic_switch example. Fixes https://github.com/espressif/esp-matter/issues/211 Added two fixed-labels using nvs in the generic_switch example. Added the mfg generated binary file 20202020_3841.bin to flash at the specified address after flashing the firmware. --- examples/generic_switch/README.md | 23 +++++++++++++++++- examples/generic_switch/main/app_main.cpp | 19 +++++++++++++++ .../mfg_binaries/20202020_3841.bin | Bin 0 -> 24576 bytes examples/generic_switch/sdkconfig.defaults | 4 +++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 examples/generic_switch/mfg_binaries/20202020_3841.bin diff --git a/examples/generic_switch/README.md b/examples/generic_switch/README.md index 251ef0696..27aa9d6aa 100644 --- a/examples/generic_switch/README.md +++ b/examples/generic_switch/README.md @@ -2,12 +2,33 @@ This example creates a Generic Switch device using the ESP Matter data model. +This example aims to demonstrate the use of Fixed Label Cluster which provides a feature for the device to tag an endpoint with zero or more read-only labels using nvs api. + +Note: + In order to retrieve the label-list from the fixed-label cluster the two options: + ``CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER`` and ``CONFIG_ENABLE_ESP32_DEVICE_INFO_PROVIDER`` have been set through sdkcofig.defaults. See the [docs](https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html) for more information about building and flashing the firmware. ## 1. Additional Environment Setup -No additional setup is required. +The steps below should be followed in order to access the fixed-labels. +- If monitoring the device using ``idf.py monitor``,press `` Ctrl + ]`` to stop the process. +- The following command must be executed to flash the mfg partition: +``` +esptool.py -p [port-name] write_flash 0x10000 mfg_binaries/20202020_3841.bin +``` +- Execute the command ``idf.py monitor`` +- Commission the device with ``discriminator: 20202020``and `` passcode: 3841`` +- Command: +``` +chip-tool pairing ble-wifi 0x7283 [ssid] [password] 20202020 3841 +``` +- To read the fixed-labels, use chip-tool. +- Command : +``` +chip-tool fixedlabels read label-list 0x7283 1 +``` ## 2. Post Commissioning Setup diff --git a/examples/generic_switch/main/app_main.cpp b/examples/generic_switch/main/app_main.cpp index 9d74e3716..ce6398a92 100644 --- a/examples/generic_switch/main/app_main.cpp +++ b/examples/generic_switch/main/app_main.cpp @@ -107,6 +107,9 @@ extern "C" void app_main() switch_endpoint_id = endpoint::get_id(endpoint); ESP_LOGI(TAG, "Generic Switch created with endpoint_id %d", switch_endpoint_id); + cluster::fixed_label::config_t fl_config; + cluster_t *fl_cluster = cluster::fixed_label::create(endpoint, &fl_config, CLUSTER_FLAG_SERVER); + /* Add additional features to the node */ cluster_t *cluster = cluster::get(endpoint, Switch::Id); #if CONFIG_GENERIC_SWITCH_TYPE_LATCHING @@ -122,6 +125,22 @@ extern "C" void app_main() ESP_LOGE(TAG, "Matter start failed: %d", err); } + nvs_handle_t handle; + nvs_open_from_partition(CONFIG_CHIP_FACTORY_NAMESPACE_PARTITION_LABEL, "chip-factory", NVS_READWRITE, &handle); + + int32_t out_value = 0; + if (nvs_get_i32(handle, "fl-sz/1", &out_value) == ESP_ERR_NVS_NOT_FOUND) + { + nvs_set_i32(handle, "fl-sz/1", 2); + nvs_set_str(handle, "fl-k/1/0", "myEP1LBL1"); + nvs_set_str(handle, "fl-v/1/0", "valEP1LBL1"); + nvs_set_str(handle, "fl-k/1/1", "myEP1LBL2"); + nvs_set_str(handle, "fl-v/1/1", "valEP1LBL2"); + } + + nvs_commit(handle); + nvs_close(handle); + #if CONFIG_ENABLE_CHIP_SHELL esp_matter::console::diagnostics_register_commands(); esp_matter::console::wifi_register_commands(); diff --git a/examples/generic_switch/mfg_binaries/20202020_3841.bin b/examples/generic_switch/mfg_binaries/20202020_3841.bin new file mode 100644 index 0000000000000000000000000000000000000000..692529fa4deb049ab733b0776f95f0067f20970c GIT binary patch literal 24576 zcmeI#Pixa~7zglV8zNrxEmQ;#CD=A?lO2Y%w6&dGWo}uQcrneN_GjCq&7b}QQDGj$ z_h1i-2N6UBVPgjmzJMJCK^%JndX-^JX2U?*OApe+_qpWoJilMQ`Q-GRdY(u5_1k~` zTYJpG{u{rh^}<<-roD&NlW$6cbQoP$9Mc*G_tBF9dWH6uUbG`Bu@#H7i6Q$FLH{yE z1tUTK^~HA-aWqSIh-om2=^74o<@%%_S@s_NI{IkKEho4)EXF_W3_tCUdVKY^D>mXO zsjf5y`$1ldZD-j;KjVrUIc}?0Dk=5K_AXZt*3MoS1`qQ^E_esy&)0gIMRcMC(a!3r zKRmvtey=8O$=y~i)2}wNoRj9Ay0D{@>>#R0eZG{^P3G&WILy{WlH)pd zyXBwMMy}K>Xa#${p_GR?r%8nM7I88I=|+CATB)b*Y~HO_%0;d#v5qK|*sj=Vj&?h8 zSzx14Y11y4vCP`k+~H>geuHP8-qQ@#v>2jJ^8fVzYA_S@ufG3cb}UnM73X~5@wxA% zAN@ny|9-i}7;gLT1rh)B&6BOZ8cWt#F3u%&T~}*bT23fxdXS>jGGqV$`r+_s-g|Kl0uX=z1Rwwb2tWV= k5P$##AOHafKmY;|fB*y_009U<00Izz00bZaf&VA)2L`HK$N&HU literal 0 HcmV?d00001 diff --git a/examples/generic_switch/sdkconfig.defaults b/examples/generic_switch/sdkconfig.defaults index b9730e305..a759ded2d 100644 --- a/examples/generic_switch/sdkconfig.defaults +++ b/examples/generic_switch/sdkconfig.defaults @@ -36,3 +36,7 @@ CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n # Disable DS Peripheral CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n + +# Enable for fixed-label +CONFIG_ENABLE_ESP32_FACTORY_DATA_PROVIDER=y +CONFIG_ENABLE_ESP32_DEVICE_INFO_PROVIDER=y