Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using analog input clusters in esp-zigbee-sdk (TZ-1142) #431

Open
Daniel-Craciun opened this issue Sep 15, 2024 · 8 comments
Open

Using analog input clusters in esp-zigbee-sdk (TZ-1142) #431

Daniel-Craciun opened this issue Sep 15, 2024 · 8 comments
Labels

Comments

@Daniel-Craciun
Copy link

Daniel-Craciun commented Sep 15, 2024

Question

Hello,

I'm currently trying to create a presence sensor in zigbee where, I am trying to advertise presence detection, detection distance etc. I'm attempting to use the analog input clusters provided by the ZCl but, I am struggling to get it working. I've looked everywhere for a possible example using analog input clusters but, to no luck.

I'm using zigbee sdk version ~1.5.0 and esp-idf version 5.1.3

Any help would be much appreciated :)

Additional context.

No response

@github-actions github-actions bot changed the title Using analog input clusters in esp-zigbee-sdk Using analog input clusters in esp-zigbee-sdk (TZ-1142) Sep 15, 2024
@prairiesnpr
Copy link

I have an example here, it's a bit rough, but it does show how to use an Analog Input. https://github.com/prairiesnpr/esp_zha_test_bench

@Daniel-Craciun
Copy link
Author

Thank you for the example it was very helpful.

Unfortunately I keep having this error which I don't know how to fix. I've followed exactly the example and I get this error Zigbee stack assertion failed /builds/thread_zigbee/esp-zboss/components/esp_zb_sdk/src/esp_zigbee_zcl_command.c:325 when I run esp_zb_zcl_report_attr_cmd_req.

For context I'm running this code on the ESP32C6 as an end device type.

Any help would be very much appreciated :)

@prairiesnpr
Copy link

I just flashed this to an ESP32C6 mini and it runs without issue. I'm have mine configured as a router, but that shouldn't matter, I've tested as an end device also. You are flashing the project as cloned from github or did you just follow as a general outline? Would need sample code to comment further, if it's not the same project.

@Daniel-Craciun
Copy link
Author

Daniel-Craciun commented Sep 19, 2024

I have cloned your repo and flashed your exact code on my ESP32C6 mini configured as an end device and I still have the same error as before. Is there anything extra I need to do? such as configuring any parameters in the menuconfig?

Screenshot 2024-09-19 at 19 05 59

@prairiesnpr
Copy link

This is the config I used on mine, maybe compare to what you have?
https://github.com/prairiesnpr/esp_zha_test_bench/blob/master/sdkconfig-c6

@prairiesnpr
Copy link

prairiesnpr commented Sep 19, 2024

Ok, I think your issue is you need to update main.h to reflect you are building an end device. https://github.com/prairiesnpr/esp_zha_test_bench/blob/fcad8d2fe90ae8f3a62bffb625988fd6e84d5f01/main/main.h#L36

Change ESP_ZB_DEVICE_TYPE_ROUTER to ESP_ZB_DEVICE_TYPE_ED

@Daniel-Craciun
Copy link
Author

Daniel-Craciun commented Sep 20, 2024

I've finally managed to get your example working :)

The issue was not about using the incorrect zigbee endpoint type, however it was the fact that I did not initialise the nvs hence why you see an error in the previous image I've shown. I have inserted the nvs init code before the esp_zb_platform_config function and everything works now fine. For reference this is the code I added incase others have an issue.

// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK( nvs_flash_erase() );
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );

Many thanks for the example which I will now use as a boilerplate code for my presence sensor! I will leave the issue open incase of any other errors (hopefully no more!).

@Daniel-Craciun
Copy link
Author

Daniel-Craciun commented Sep 21, 2024

Hello this is a follow up incase anyone has any issues with this.

If you are writing Zigbee code and you are changing the endpoints, clusters and attribute ids. You MUST always erase the chip flash before flashing your new code with the new updated ids. As I think the old ids are not being cleared out if you don't erase the flash.

For example in esp-idf you should run the command idf.py -p (PORT) erase-flash before uploading any new code to ensure nothing is cached from previous projects uploaded to the board. This command helped me to get the analog input cluster example code finally working!

Many thanks again for this code sample it is much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants