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
  • Thanks a lot for your help, Tony. The link is quite useful for me to understand the mechanism of CCCD. After reading the link of Bluetooth Low Energy Pairing Guide,I understand the mechanism for storing and restoring the bonding information and system attributes ,which is important to freely reconnect without do the bonding procedure again and mainly include CCCD,but the document is too old so I can't find the functions related to System Attributes in the latest SDK . Then I tried several methods with respect to modifying the System Attributes which includes CCCD configuration. Finally I saw this question about 'automatically start notification', the link is righthere.By following the steps using two main functions sd_ble_gatts_sys_attr_set and sd_ble_gatts_sys_attr_get , I finally enable the notification successfully on the GATT server side.Now we could notify the value as long as building the connection without waiting the enabled notification from GATT client. However ,if we want to let the GATT client side(I use Android mobile phone as the GATT client) receive the value notified we should firstly set the notification enable on the GATT client side ,notice that just setting the notification enable and don't need enable the CCCD on the GATT client. As tony said , doing the work like this dose not make any meaningful sense because we don't know the client's state whether it is ready to receive the value notified from server, it is kind of wasting power. I use this just to test when doing the specific connection of two known peers,actually we put the control right to the server not the client with the prerequisite of client all the time running to wait the notification from server.Anyway, thanks tony again.

Reply
  • Thanks a lot for your help, Tony. The link is quite useful for me to understand the mechanism of CCCD. After reading the link of Bluetooth Low Energy Pairing Guide,I understand the mechanism for storing and restoring the bonding information and system attributes ,which is important to freely reconnect without do the bonding procedure again and mainly include CCCD,but the document is too old so I can't find the functions related to System Attributes in the latest SDK . Then I tried several methods with respect to modifying the System Attributes which includes CCCD configuration. Finally I saw this question about 'automatically start notification', the link is righthere.By following the steps using two main functions sd_ble_gatts_sys_attr_set and sd_ble_gatts_sys_attr_get , I finally enable the notification successfully on the GATT server side.Now we could notify the value as long as building the connection without waiting the enabled notification from GATT client. However ,if we want to let the GATT client side(I use Android mobile phone as the GATT client) receive the value notified we should firstly set the notification enable on the GATT client side ,notice that just setting the notification enable and don't need enable the CCCD on the GATT client. As tony said , doing the work like this dose not make any meaningful sense because we don't know the client's state whether it is ready to receive the value notified from server, it is kind of wasting power. I use this just to test when doing the specific connection of two known peers,actually we put the control right to the server not the client with the prerequisite of client all the time running to wait the notification from server.Anyway, thanks tony again.

Children
No Data
Related