<?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>BLE Central connect to same device mulitple times, and client service reacts to events twice.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/54873/ble-central-connect-to-same-device-mulitple-times-and-client-service-reacts-to-events-twice</link><description>I&amp;#39;ve made a project that scans and advertises. 
 The first problem: When i have one central link, I get the problem that the client service gets events twice. 
 &amp;lt;debug&amp;gt; ble_db_disc: Starting discovery of service with UUID 0x180F on connection handle 0x0</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 27 Nov 2019 13:17:02 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/54873/ble-central-connect-to-same-device-mulitple-times-and-client-service-reacts-to-events-twice" /><item><title>RE: BLE Central connect to same device mulitple times, and client service reacts to events twice.</title><link>https://devzone.nordicsemi.com/thread/222360?ContentTypeID=1</link><pubDate>Wed, 27 Nov 2019 13:17:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e057cbe2-b9cf-4fed-9f1b-8c2598ed0f73</guid><dc:creator>shn</dc:creator><description>&lt;p&gt;Hey,&lt;br /&gt;&lt;br /&gt;I solved the problem, my application was reacting to the event twice.&lt;br /&gt;&lt;br /&gt;This happened by, using both:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;strong&gt;ble_bas_c_on_ble_evt(p_ble_evt,&amp;nbsp;&amp;amp;m_bas_c);&lt;/strong&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void event_dispatcher(ble_evt_t const* p_ble_evt, void* p_context) {
    uint16_t conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;  // connection handle
    uint16_t role        = ble_conn_state_role(conn_handle);    // fetch role
        
   if(role == BLE_GAP_ROLE_PERIPH || ble_evt_is_advertising_timeout(p_ble_evt)) {

        on_ble_peripheral_event(p_ble_evt);

    } else if((role == BLE_GAP_ROLE_CENTRAL) || (p_ble_evt-&amp;gt;header.evt_id == BLE_GAP_EVT_ADV_REPORT)) {

        on_ble_central_event(p_ble_evt);
        ble_bas_c_on_ble_evt(p_ble_evt, &amp;amp;m_bas_c);
  
}&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;and&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;strong&gt;ble_bas_on_db_disc_evt(&amp;amp;m_bas_c,&amp;nbsp;p_scan_evt);&lt;/strong&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;in the db_discovery_handler.&lt;br /&gt;&lt;br /&gt;This made the event happen simultaneously, in retrospect this makes sense. I&amp;#39;ve revmoved the first occurance.&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central connect to same device mulitple times, and client service reacts to events twice.</title><link>https://devzone.nordicsemi.com/thread/222274?ContentTypeID=1</link><pubDate>Wed, 27 Nov 2019 10:07:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52c52a46-72da-4e1e-aa58-1cd895e1447d</guid><dc:creator>shn</dc:creator><description>&lt;p&gt;Hey,&lt;br /&gt;&lt;br /&gt;Okay - I&amp;nbsp;will look into why the db_discovery handler get&amp;#39;s called twice.&lt;br /&gt;It seems to a duplication of events or calls... I will update on when i find the error.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Then I will start creating the address table - Does the SDK have anything i should use to create this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central connect to same device mulitple times, and client service reacts to events twice.</title><link>https://devzone.nordicsemi.com/thread/222270?ContentTypeID=1</link><pubDate>Wed, 27 Nov 2019 09:54:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2774b7e-b1b7-4203-b7ef-e9ad57bb0637</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;We don&amp;#39;t have any examples of this that I know of, unfortunately. One of the sides (Central or peripheral) is usually limited to one connection so it&amp;#39;s normally not a problem. The peer address is included in the adv. report event and the GAP connect event. I would maybe add the address to the table on the connect event, and remove it when it disconnects. You can use the connection handle as an index for your table.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central connect to same device mulitple times, and client service reacts to events twice.</title><link>https://devzone.nordicsemi.com/thread/222264?ContentTypeID=1</link><pubDate>Wed, 27 Nov 2019 09:26:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bac1ce23-af23-4a9a-bc9a-5a01ed65c4a3</guid><dc:creator>shn</dc:creator><description>&lt;p&gt;Hey,&lt;br /&gt;&lt;br /&gt;.connect_if_match is enabled. So a good idea to do the address table - is there any example of how to implement that?&lt;br /&gt;&lt;br /&gt;The &amp;quot;SD READ/WRITE API returns error.&amp;quot; happens the very first time, on connection...&amp;nbsp;The error code is 17 - So I think it&amp;#39;s just because the central device makes requests a READ twice &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central connect to same device mulitple times, and client service reacts to events twice.</title><link>https://devzone.nordicsemi.com/thread/222258?ContentTypeID=1</link><pubDate>Wed, 27 Nov 2019 09:13:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ff9af6a-90be-4269-9d75-c843d0b75070</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;In the first problem, It looks like the read request is being sent twice. I suggest to add more logging in ble_bas_c.c::tx_buffer_process() to confirm&amp;nbsp;if the read request is duplicated. Also, do you always get the &lt;em&gt;&amp;quot;&lt;/em&gt;&lt;span&gt;&lt;em&gt;SD Read/Write API returns error. This message sending will be attempted again..&amp;quot;&lt;/em&gt;&amp;nbsp;message when reading the battery characteristic? Please check the returned error code from&amp;nbsp;sd_ble_gattc_read() in that case.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The scanner module will connect to anything&amp;nbsp;matching&amp;nbsp;the filter settings&amp;nbsp;when it&amp;#39;s initialized with &amp;quot;.connect_if_match&amp;quot; enabled. So I suggest to disable this option and instead make the decision to connect in your scanner callback. One way to do it could be to&amp;nbsp;manage a RAM table with the addresses of all connected peers, then when you get the&amp;nbsp;&amp;nbsp;NRF_BLE_SCAN_EVT_FILTER_MATCH you can check if the discovered device is already in the address list or not.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>