This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How does one get an internal firmware notification when an external device reads a characteristic?

I have a firmware build that uses the nRF52832 (SoftDevice S132) to return a variety of read characteristics to an external device. So far so good. I can verify that the values are read properly when using nRF connect or a mobile app.

How can I get some form of internal notification in firmware when an external devices READS one or more of these characteristics?

The application is to be able to flash an LED every time one of these read transactions occurs.

I have seen a few posts that suggest that "Authorized Reads" is the best approach for doing this but I haven't seen any clear concise code that demonstrates how this is performed.

Thanks for any advice.

Parents
  • One of the parameters to sd_ble_gatts_characteristic_add() is the attribute metadata, ble_gatts_attr_md_t.  Set the element .rd_auth = 1.

    Then in your ble event handler (depends on sdk version), add a case for BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST.  In that case, check the request for BLE_GATTS_AUTHORIZE_TYPE_READ.  If so, you've got a read request for the indicated characteristic.

    Note that this is not just a notification, you will need to provide the value that is being read rather than the gatts subsystem managing that for you. 

    I didn't find an example that shows it clearly, but the above should get you started.

    Richard

Reply
  • One of the parameters to sd_ble_gatts_characteristic_add() is the attribute metadata, ble_gatts_attr_md_t.  Set the element .rd_auth = 1.

    Then in your ble event handler (depends on sdk version), add a case for BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST.  In that case, check the request for BLE_GATTS_AUTHORIZE_TYPE_READ.  If so, you've got a read request for the indicated characteristic.

    Note that this is not just a notification, you will need to provide the value that is being read rather than the gatts subsystem managing that for you. 

    I didn't find an example that shows it clearly, but the above should get you started.

    Richard

Children
No Data
Related