espressif / esp-homekit-sdk

550 stars 99 forks source link

Sync service state manually when using physical button #24

Closed cocofly59 closed 3 years ago

cocofly59 commented 3 years ago

Hi,

I'm making a basic connected light with a physical switch using the lightbulb example. Everything works perfectly except that when I'm using the physical switch, the light state is not sync with the server (for example, the iPhone shows the light is on instead of off).

I'm unable to find the way to notify the server that the light' state has changed. Any idea?

shahpiyushv commented 3 years ago

@cocofly59 , to report values to the iPhone via async event notifications, you just need to use this API: `int hap_char_update_val(hap_char_t hc, hap_val_t val);

You can find sample usage here. I hope this answers your query.

cocofly59 commented 3 years ago

Thank you, it mostly answer my query.

I will add that you need to use the function '_hap_char_t hap_serv_get_char_by_uuid(hap_serv_t hs, const char uuid)_ ' to access the characteristic you want to change (and '_const hap_val_t hap_char_get_val(hap_chart *hc)' if you want to get the old value).