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

How to enable notification on the peripheral side?

Hi , I am using nRF51822 as a ble_peripheral to send the sensor data to the phone. I already add a characteristic with the property of notify , and it could work when using MCP to test. But now I want to send the data autonomously without the enabled notification from phone. I find a function called 'sd_ble_gatts_value_set' to enable the cccd value but it do not work as I expect. I researched some questions about cccd , as said it could be retained by both sides when bounding. I am not exactly aware of what that means.So I wonder if I could enable notification on the peripheral side without enabling from phone and how to do this? Thanks. Forget to mention that I got the err_code of NRF_ERROR_FORBIDDEN when calling the function of 'sd_ble_gatts_value_set' to set the cccd value with cccd handle.

Parents
  • Hi Evan,

    To be clear, by "peripheral side" I assume you mean "server side"? Your phone is the GATT client in this case, and your nRF51822 + sensor is the GATT server which has data that your phone wants to receive. Just wanted to make the technicality clear since there's nothing stopping a GAP peripheral from being both a GATT server and a GATT client.

    Under that assumption, it is not possible to autonomously send notifications of a characteristic value from your nRF51 (server) to your phone (client) without the client enabling notifications by writing a "1" to the CCCD for that characteristic. The reason for that is nicely written in the Client Characteristic Configuration Descriptor section of the Getting Started With Bluetooth Low Energy if you want detailed information. But long story short, the server cannot autonomously send notifications to the client because the server has no idea if the client knows about that characteristic yet (it may not have performed a full service or characteristic discovery), so the client won't be able to identify the characteristic handle that comes in the notification from the server anyway if the client has not discovered that characteristic.

    And to answer your question about retaining the CCCD while bonding: if the client bonds with the server and enables the notification for a characteristic, then on every subsequent connection while they are bonded the CCCD for that particular characteristic will automatically be set enable notifications since the server now remembers that the client wanted notifications for that characteristic.

    So in your case, the closest thing to autonomous notifications to your phone is to bond with the nRF51 on the first connection, and then enable notifications to the characteristics that you want. This way your nRF51 will remember that your phone wants notifications and automatically start sending them on subsequent connections.

    Hope this helps.

Reply
  • Hi Evan,

    To be clear, by "peripheral side" I assume you mean "server side"? Your phone is the GATT client in this case, and your nRF51822 + sensor is the GATT server which has data that your phone wants to receive. Just wanted to make the technicality clear since there's nothing stopping a GAP peripheral from being both a GATT server and a GATT client.

    Under that assumption, it is not possible to autonomously send notifications of a characteristic value from your nRF51 (server) to your phone (client) without the client enabling notifications by writing a "1" to the CCCD for that characteristic. The reason for that is nicely written in the Client Characteristic Configuration Descriptor section of the Getting Started With Bluetooth Low Energy if you want detailed information. But long story short, the server cannot autonomously send notifications to the client because the server has no idea if the client knows about that characteristic yet (it may not have performed a full service or characteristic discovery), so the client won't be able to identify the characteristic handle that comes in the notification from the server anyway if the client has not discovered that characteristic.

    And to answer your question about retaining the CCCD while bonding: if the client bonds with the server and enables the notification for a characteristic, then on every subsequent connection while they are bonded the CCCD for that particular characteristic will automatically be set enable notifications since the server now remembers that the client wanted notifications for that characteristic.

    So in your case, the closest thing to autonomous notifications to your phone is to bond with the nRF51 on the first connection, and then enable notifications to the characteristics that you want. This way your nRF51 will remember that your phone wants notifications and automatically start sending them on subsequent connections.

    Hope this helps.

Children
No Data
Related