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

How to implement automatic shutdown in switch module and update homekit state #91

Open
ilovn opened this issue Aug 8, 2022 · 7 comments

Comments

@ilovn
Copy link

ilovn commented Aug 8, 2022

I implemented a switch module through the code example, which controls the device through the gpio control output. Now I hope to automatically turn off 30 seconds after opening. I realized the shutdown through the timer, but I can't update the state in the homekit.

@shahpiyushv
Copy link
Collaborator

@ilovn You can maintain a pointer of the characteristic and update it as shown in this example. If you do not want to maintain the pointer, you can also fetch it at runtime using a combination of hap_acc_get_by_aid(), hap_acc_get_serv_by_uuid() and hap_serv_get_char_by_uuid, all of which can be found in hap.h

@ilovn
Copy link
Author

ilovn commented Aug 9, 2022

When I use GPIO18 to control the relay to realize the circuit on and off, but updating the Homekit status still does not work properly, which UUID type with hap_serv_get_char_by_uuid or hap_acc_get_serv_by_uuid ? I got the aid from log,but hap_acc_get_by_aid still does not work.

@shahpiyushv
Copy link
Collaborator

Since your implementation is a simple switch, you just need to call hap_acc_get_by_aid(1). This pointer is created and returned by hap_acc_create() and so you can keep a copy of that too. Standard service UUIDs can be found here and standard characteristic UUIDs can be found here. UUID for switch is HAP_SERV_UUID_SWITCH, whereas that of outlet is HAP_SERV_UUID_SWITCH. The UUID for ON characteristic is HAP_CHAR_UUID_ON.

@ilovn
Copy link
Author

ilovn commented Aug 10, 2022

Through the UUID or aid you provide, the code can run normally, but the switch status in the Home App remains unchanged.

@shahpiyushv
Copy link
Collaborator

Has iOS enabled the events? You can verify this by checking for prints like these in the serial terminal logs

Events enabled for aid=x iid=y

If you see this, whenver you call hap_char_update_val(), you should also see prints like

Value Changed
Notification Sent

You may also enable additional debugging using hap_http_debug_enable() once before calling hap_start() so that we can more logs to understand the issue.

@NguyenVux
Copy link

mine print out Events disabled for aid=x iid=y how can i enable it

@shahpiyushv
Copy link
Collaborator

Event subscription is managed by the iOS layer and is not in user's or accessory's control. If the serial terminal prints Events disabled for aid=x iid=y it means that iOS has explicitly disabled it since it is no more required. This typically happens when the Home app goes in background.

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

No branches or pull requests

3 participants