espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.45k stars 7.25k forks source link

BT GATTS: How to tell when client subscribed to notifications? #1204

Closed rojer closed 6 years ago

rojer commented 6 years ago

My application is a GATT server and it can send notifications in certain cases. However, i would like to know if the client actually subscribed/registered to receive them, as i don't want to waste resources unless client is actually subscribed. I don't see any GATTS event raised when client registers for notifications, so - is there any other way to tell?

negativekelvin commented 6 years ago

It should come as ESP_GATTS_WRITE_EVT for CCCD

rojer commented 6 years ago

i have handlers for all the GATTS events and notification reg/unreg do not seem trigger any of them at present. also - what is CCCD?

negativekelvin commented 6 years ago

A writable descriptor that allows client to configure notifications for that characteristic

https://github.com/espressif/esp-idf/blob/master/examples/bluetooth/gatt_server_service_table/main/gatts_table_creat_demo.c#L170

rojer commented 6 years ago

um... so, as a service, am i supposed to do anything special to receive those events? notifications themselves work fine - when i send them (blindly), the clients receives them just fine. but i don't get any GATTS events when client regs/unregs.

negativekelvin commented 6 years ago

https://github.com/espressif/esp-idf/blob/master/examples/bluetooth/gatt_server/main/gatts_demo.c#L367

rojer commented 6 years ago

that... is not obvious :) but really, i should re-examine the examples again, looks like they've changed a lot.

but i'm definitely not seeing write events, i would've. weird. but i need to verify that my client (BLE Scanner app) actually sends them.

negativekelvin commented 6 years ago

Client will not register if it doesn't discover CCCD

rojer commented 6 years ago

figured it out, thanks!