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 000000000..692529fa4 Binary files /dev/null and b/examples/generic_switch/mfg_binaries/20202020_3841.bin differ 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