espressif / esp-homekit-sdk

550 stars 99 forks source link

Characteristic Notifcations #29

Closed shaurya0406 closed 3 years ago

shaurya0406 commented 3 years ago

How to update the temperature sensor value in the Home app at a particular interval in a function other than the read callback. I have tried hap_char_update_val() and my characteristic has the HAP_CHAR_PERM_PR and HAP_CHAR_PERM_EV permissions. But this doesn't automatically update in Home iOS app. I have to refresh the app or ask Siri, which means that only the read callback is being triggered. What am I doing wrong?

shahpiyushv commented 3 years ago

@shaurya0406 , hap_char_update_val() indeed is sufficient to invoke event notification. However, the controller first needs to subscribe to it. Can you call the function hap_http_debug_enable() before hap_start() and see if the controller is subscribing to the events? Even without these additional debug messages, you should atleast see text like this if the controller is subscribing to the event notifications

Events Enabled for aid=1 iid=12
shaurya0406 commented 3 years ago

Thank you for the quick reply. I am getting these logs: Events Enabled for aid=3 iid=9 Events Enabled for aid=4 iid=9 Events Enabled for aid=4 iid=11 Events Enabled for aid=2 iid=11 Events Enabled for aid=2 iid=14

This is for bridge accessory

shaurya0406 commented 3 years ago

It was an error on my side. I forgot to call hap_serv_get_char_by_uuid() in the bridge thread so I was updating to unknown characteristic. Thank you and I am closing this issue

skylli commented 3 years ago

@shahpiyushv

HomeKit App still can't get the notification from outlet when run examples/smart_outlet.

I just idf.py build the examples/smart_outlet project, and burn to my esp32 board, but my homekit app still can receive any notification on my iphone. My esp32 board can receive the http request from homekit app when i tap the button. Here is my log:

Socket fd: 51; HTTP Request GET /characteristics?id=1.12
Generating HTTP Response
{"characteristics":[{"aid":1,"iid":12,"value":true}]}
Socket fd: 51; HTTP Request PUT /characteristics
Data Received: {"characteristics":[{"aid":1,"iid":12,"value":0}]}
I (521178) HAP outlet: Received Write. Outlet Off
_hc->format 1  val 0 old val 1
Value Changed 1
E (524548) Button:  press
Value Changed 1
Notification Sent
Socket fd: 51; Event message: {"characteristics":[{"aid":1,"iid":13,"value":false}]}
D (524558) [system, 51]: handle tap event
I (524558) HAP outlet: Outlet-In-Use triggered [0]

What am I going to do to get device notification?

shahpiyushv commented 3 years ago

@skylli , how exactly are you checking this? You have to tap and hold the Outlet tile n the Home app, then go to Settings (gear icon on bottom right) and there you can see the outlet in use status changing. Once you press the button, it will show the value as No, and on releasing it will show Yes. Check this screen recording.

https://user-images.githubusercontent.com/8659527/111644397-cda14d80-8825-11eb-9409-b30e8cea68aa.MP4

P.S. There could be other ways of checking Outlet-In-Use, but this is where I check it.

skylli commented 3 years ago

@shahpiyushv
Thank you for your quick reply I didn't notice that there were no hap_serv_get_char_by_uuid(service, HAP_CHAR_UUID_ON) in this example.

leotordo commented 9 months ago

hap_serv_get_char_by_uuid()

Hello, I've a similar problem with my board. I driver a led from Home app and works fine. I've a mechanical switch to switch on/off the led that I read on a input pin of my ESP32. Can you give me help to update the status on the iPhone? The led turns off, but on the Home app it remains on Thanks Andrea