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

Add service while connection

Dears,

I'd like to add service while connection.

Now I am using UART service and want to add HID service when I put button.

How to add HID service while connection?

Could you provide example code?

SDK : nRF5_SDK_14.2.0_17b948a

Base code : ble_app_uart

App : Android

Thank you.

Best Regards,

Joyce

Parents
  • Hi,

    It is possible to add a service in an active connection. The central would need to do the service discovery again. So you should notify the central with the sd_ble_gatts_service_changed() after you have added the service. On a button press, you could then call the hids_init()/service_init() and then call the sd_ble_gatts_service_changed. I haven’t tested how the phone behaves when a HID service is suddenly added, so you should test if the phone “activates” the HID functionality after the service is added.

    Since you are using ble_app_uart, the first step should be to combine one of the HID examples (either ble_app_hids_keyboard or ble_app_hids_mouse) with the ble_app_uart examples. After that you can look into adding the button press functionally. For an example on how to add button press interrupt, take a look at the pin_change_int example in the SDK folder SDK_folder\examples\peripheral\pin_change_int.

Reply
  • Hi,

    It is possible to add a service in an active connection. The central would need to do the service discovery again. So you should notify the central with the sd_ble_gatts_service_changed() after you have added the service. On a button press, you could then call the hids_init()/service_init() and then call the sd_ble_gatts_service_changed. I haven’t tested how the phone behaves when a HID service is suddenly added, so you should test if the phone “activates” the HID functionality after the service is added.

    Since you are using ble_app_uart, the first step should be to combine one of the HID examples (either ble_app_hids_keyboard or ble_app_hids_mouse) with the ble_app_uart examples. After that you can look into adding the button press functionally. For an example on how to add button press interrupt, take a look at the pin_change_int example in the SDK folder SDK_folder\examples\peripheral\pin_change_int.

Children
Related