<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Add service while connection</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/30964/add-service-while-connection</link><description>Dears, 
 
 I&amp;#39;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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 09 Mar 2018 09:14:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/30964/add-service-while-connection" /><item><title>RE: Add service while connection</title><link>https://devzone.nordicsemi.com/thread/123575?ContentTypeID=1</link><pubDate>Fri, 09 Mar 2018 09:14:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7fdf9cda-4f2b-4d6e-bcc6-d9cf80dbf3a5</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi Giang,&lt;/p&gt;
&lt;p&gt;You could try something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;ret_code_t send_service_changed(uint16_t conn_handle)
{
    static uint16_t start_handle;
    const  uint16_t end_handle = 0xFFFF;
    ret_code_t err_code;

    err_code = sd_ble_gatts_initial_user_handle_get(&amp;amp;start_handle);

    if (err_code != NRF_SUCCESS)
    {
        return NRF_ERROR_INTERNAL;
    }

    do
    {
        err_code = sd_ble_gatts_service_changed(conn_handle, start_handle, end_handle);
        if (err_code == BLE_ERROR_INVALID_ATTR_HANDLE)
        {
            start_handle += 1;
        }
    } while (err_code == BLE_ERROR_INVALID_ATTR_HANDLE);

    return err_code;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Add service while connection</title><link>https://devzone.nordicsemi.com/thread/123343?ContentTypeID=1</link><pubDate>Thu, 08 Mar 2018 06:57:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb63d22b-102f-4ded-aaf1-601c567a5fe1</guid><dc:creator>Giang</dc:creator><description>&lt;p&gt;Hi Sigurd, how to calculate&amp;nbsp;start_handle and end_handle in&amp;nbsp;sd_ble_gatts_service_changed . I want to and bas_service to nus_service via button . Thank&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Add service while connection</title><link>https://devzone.nordicsemi.com/thread/123095?ContentTypeID=1</link><pubDate>Tue, 06 Mar 2018 14:21:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d58ede7f-e232-431b-ab8e-12a003aaa06f</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;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&amp;rsquo;t tested how the phone behaves when a HID service is suddenly added, so you should test if the phone &amp;ldquo;activates&amp;rdquo; the HID functionality after the service is added. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Since you are using &lt;/span&gt;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. &lt;span&gt;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.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>