On Mon, Nov 28, 2016 at 03:42:01PM -0500, David G. Simmons wrote:
> It's my understanding from that code that the callback function for all the 
> characteristics is registered in the gatt_srv table, and that in e example 
> they all have the same callback function, namely gatt_svr_chr_access_alert. 
> So I looked there for further help. And indeed, in 
> gatt_svr_chr_access_alert(), I see what is supposed to happen when the 
> various characteristics are accessed.
> 
> case GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID:
>         assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
>         rc = os_mbuf_append(ctxt->om, &gatt_svr_new_alert_cat,
>                             sizeof gatt_svr_new_alert_cat);
>         return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
> 
> is called when I read the GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID characteristic 
> -- and I've verified this via a connection through LightBlue.  
> GATT_SVR_CHR_NEW_ALERT is a 'subscribable' UUID, and I would expect that 
> 
> case GATT_SVR_CHR_NEW_ALERT:
>         if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
>             rc = gatt_svr_chr_write(ctxt->om, 0,
>                                     sizeof gatt_svr_new_alert_val,
>                                     gatt_svr_new_alert_val,
>                                     &gatt_svr_new_alert_val_len);
>             return rc;
>         } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
>             rc = os_mbuf_append(ctxt->om, &gatt_svr_new_alert_val,
>                                 sizeof gatt_svr_new_alert_val);
>             return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
>         }
> 
> would get called when I subscribe to this characteristic. But it does not. 
> 
> So, if I want to have a subscribable service characteristic, How do I 
> implement that, and where does the characteristic value get updated so that 
> it is propagated to the connected device (if any)? 

I implemented several Notify characteristics for HID over GATT here:

https://github.com/mikeryan/SlideQuacker/blob/master/apps/quacker/src/gatt_svr.c#L146-L196

The READ and WRITE CHR callbacks aren't called when you "subscribed"
because the writes are against the CCC Descriptor. You roughly don't
have to worry about when that happens, and at least at the time I wrote
this there was no way to register a callback for when they're written
to.

To send updates to the client, you first update the characteristic value
in memory and then call ble_gatts_chr_updated() with the characteristic
handle number. Example:

https://github.com/mikeryan/SlideQuacker/blob/master/apps/quacker/src/main.c#L376-L377

I don't think there's a good way to turn a UUID into a handle number
from firmware. I looked it up using gatttool and hard coded it into my
app.

Reply via email to