espressif / esp-homekit-sdk

541 stars 98 forks source link

Anyone tried multiple devices/switches in Homekit example (MEGH-2692) #59

Open adukale opened 2 years ago

adukale commented 2 years ago

I want to integrate multiple devices/switches in Homekit example code. The homekit initialization is clear to me but I am getting confused while registering devices ans setting callbacks, so wondering if anyone has already tried this.

Thanks in advance. Any help is appreciated.

shahpiyushv commented 2 years ago

@adukale , you can check the bridge example to understand how to add multiple accessories under the same node. However, if the multiple accessories (switches in your case) are co-located i.e. part of a single physical device, you just need to add multiple switch services into the same accessory. You can either have independent callbacks for each or add some private data to each switch service (some identifier or GPIO number) and have a common callback. This line shows how to add private data and that same is used here in the callback.

adukale commented 2 years ago

@shahpiyushv Thank you for quick response. Your suggestions helped. I have modified esp_rainmaker/example/homekit_example to have 6 switches. Here is the code sample: https://github.com/adukale/homekit_6switch

I can see 6 switches in Home app in ios/HomeKit. But turning on/off anyone of them results in rebooting esp32 and it goes into bootloop sometimes. Also, the connected gpios/relayes does not change the state.

Thanks in advance.

adukale commented 2 years ago

@shahpiyushv I resolved the error. The issue was in callback functions for homekit service. Have seperated out each callbacks for services. Now control from ESP Rainmaker App & HomeKit app works flawlessly, the only issue is state is not persisted in homekit. I noticed the code: app_homekit_start(DEFALT_POWER); in app_main.c. This set power to default set and does not retain the previous state. Is there any workaround for this? Updated code: https://github.com/adukale/homekit_6switch Thank You