<?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>Multiple Custom Services</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/76196/multiple-custom-services</link><description>I wrote some code that has multiple custom services where my device acts as GATT Server. 
 I register the handler for every service (3 in total) with NRF_SDH_BLE_OBSERVER as in this example: 
 
 
 The problem is that this will result in the SoftDevice</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 10 Jun 2021 15:28:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/76196/multiple-custom-services" /><item><title>RE: Multiple Custom Services</title><link>https://devzone.nordicsemi.com/thread/314774?ContentTypeID=1</link><pubDate>Thu, 10 Jun 2021 15:28:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08cf7e46-9ef9-4ea9-8a5a-22b852a4824b</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;The SoftDevice supports multiple concurrent connections, so all API functions that are related to a specific connection need the connection handle to know which connection it applies to.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiple Custom Services</title><link>https://devzone.nordicsemi.com/thread/314757?ContentTypeID=1</link><pubDate>Thu, 10 Jun 2021 14:10:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32bcfe93-555e-4a60-a17f-bafdbf68a2d9</guid><dc:creator>Erikk</dc:creator><description>&lt;p&gt;Ok thank you!&lt;/p&gt;
&lt;p&gt;This helped me figured out that I could save the connection handle inside the if statement with the cccd_handle and would only disconnect if the ble event handle corresponded to the saved handle.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;   if ((p_evt_write-&amp;gt;handle == psBcpService-&amp;gt;rxhandle.cccd_handle) &amp;amp;&amp;amp;
       (p_evt_write-&amp;gt;len == 2))
   {
      if (p_client != NULL)
      {
    	_mymodule.UINT16_ConnHandle = psBleEvt-&amp;gt;evt.gap_evt.conn_handle;
    	
    	...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;      case BLE_GAP_EVT_DISCONNECTED:
	// Check if the disconnected device is the current  Client
	if(mymodule.UINT16_ConnHandle == psBleEvt-&amp;gt;evt.gap_evt.conn_handle){
	    mymodule.UINT16_ConnHandle = BLE_CONN_HANDLE_INVALID;
	} &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Just one thing I am not sure about. Why do we even bother to store the connection handle? I see that it is given to the DataHandler but then what can it be used for?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiple Custom Services</title><link>https://devzone.nordicsemi.com/thread/314684?ContentTypeID=1</link><pubDate>Thu, 10 Jun 2021 11:52:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18cd4145-a212-40c8-8b0b-e9be95b7ac34</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;This is how the SoftDeviec API is. You can subscribe to BLE events, and then you will get all BLE events. It is then up to the receiver to filter out what is relevant and ignore all other events. You can see how this is done in existing service implementations in the SDK.&lt;/p&gt;
&lt;p&gt;For instance, just to pick an example you can refer to components\ble\ble_services\ble_nus\ble_nus.c where you can see that in the&amp;nbsp;on_write() function that tis called for the&amp;nbsp;BLE_GATTS_EVT_WRITE event, the implementation checks if the write is to one of the two handles that can be written to in the NUS service implementation. If it is not, it is ignored.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>