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.
This commit is contained in:
shripad621git
2023-03-01 13:08:03 +05:30
parent 0dbeaa5edd
commit cfc2e10a1c
4 changed files with 45 additions and 1 deletions
+22 -1
View File
@@ -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
+19
View File
@@ -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();
@@ -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