<?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>Mismatch between connection handles in ble_nus?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/18804/mismatch-between-connection-handles-in-ble_nus</link><description>I&amp;#39;m using the nus_c service with multiple central connections. Obviously, I need the connection handle in my event handler - ble_nus_c_evt_handler(ble_nus_c_t* p_ble_nus_c, const ble_nus_c_evt_t* p_ble_nus_evt) . 
 I&amp;#39;ve noticed that when BLE_NUS_C_EVT_NUS_RX_EVT</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 21 Mar 2020 07:45:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/18804/mismatch-between-connection-handles-in-ble_nus" /><item><title>RE: Mismatch between connection handles in ble_nus?</title><link>https://devzone.nordicsemi.com/thread/240976?ContentTypeID=1</link><pubDate>Sat, 21 Mar 2020 07:45:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1722ccf-f182-413a-ac3a-44253a30325a</guid><dc:creator>Duy</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I just tested with SDK 15.3 and 16.0 and the problem is still there. The solution still works well.&lt;/p&gt;
&lt;p&gt;I added&amp;nbsp;&lt;em&gt;&lt;strong&gt;ble_nus_c_evt.conn_handle = p_ble_nus_c-&amp;gt;conn_handle;&lt;/strong&gt;&lt;/em&gt; in function&amp;nbsp;&lt;em&gt;&lt;strong&gt;on_hvx&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;**@brief     Function for handling Handle Value Notification received from the SoftDevice.
 *
 * @details   This function will uses the Handle Value Notification received from the SoftDevice
 *            and checks if it is a notification of the NUS TX characteristic from the peer. If
 *            it is, this function will decode the data and send it to the
 *            application.
 *
 * @param[in] p_ble_nus_c Pointer to the NUS Client structure.
 * @param[in] p_ble_evt   Pointer to the BLE event received.
 */
static void on_hvx(ble_nus_c_t * p_ble_nus_c, ble_evt_t const * p_ble_evt)
{
    // HVX can only occur from client sending.
    if (   (p_ble_nus_c-&amp;gt;handles.nus_tx_handle != BLE_GATT_HANDLE_INVALID)
        &amp;amp;&amp;amp; (p_ble_evt-&amp;gt;evt.gattc_evt.params.hvx.handle == p_ble_nus_c-&amp;gt;handles.nus_tx_handle)
        &amp;amp;&amp;amp; (p_ble_nus_c-&amp;gt;evt_handler != NULL))
    {
        ble_nus_c_evt_t ble_nus_c_evt;

        ble_nus_c_evt.evt_type = BLE_NUS_C_EVT_NUS_TX_EVT;
        ble_nus_c_evt.p_data   = (uint8_t *)p_ble_evt-&amp;gt;evt.gattc_evt.params.hvx.data;
        ble_nus_c_evt.data_len = p_ble_evt-&amp;gt;evt.gattc_evt.params.hvx.len;
        
        /* Modifed here to solve the problem conn_handle update */
        ble_nus_c_evt.conn_handle = p_ble_nus_c-&amp;gt;conn_handle;

        p_ble_nus_c-&amp;gt;evt_handler(p_ble_nus_c, &amp;amp;ble_nus_c_evt);
        NRF_LOG_DEBUG(&amp;quot;Client sending data.&amp;quot;);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Duy&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mismatch between connection handles in ble_nus?</title><link>https://devzone.nordicsemi.com/thread/129266?ContentTypeID=1</link><pubDate>Mon, 23 Apr 2018 06:55:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96859a74-e875-4e8e-a798-5402ab22e7aa</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi sara,&lt;/p&gt;
&lt;p&gt;It&amp;#39;s when you get the&amp;nbsp;BLE_NUS_C_EVT_DISCOVERY_COMPLETE in the function&amp;nbsp;ble_nus_c_evt_handler()&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mismatch between connection handles in ble_nus?</title><link>https://devzone.nordicsemi.com/thread/129116?ContentTypeID=1</link><pubDate>Fri, 20 Apr 2018 09:32:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79c84593-e2cf-4e25-a3b6-a7e579063381</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;Hello Sigurd,&lt;/p&gt;
&lt;p&gt;where should i set &amp;quot;ble_nus_c_handles_assign(..)&amp;quot; function?&lt;/p&gt;
&lt;p&gt;All the definition are follow the sample code as you provided.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mismatch between connection handles in ble_nus?</title><link>https://devzone.nordicsemi.com/thread/123587?ContentTypeID=1</link><pubDate>Fri, 09 Mar 2018 09:36:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e67c30d1-2964-4167-9f2d-a95a466e9842</guid><dc:creator>Kashinath</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you for you reply,&lt;/p&gt;
&lt;p&gt;Now that issue solved, now multi connection to central is working, but it is not printing data received from peripheral, means next event is not working, i getting output like this in terminal:&lt;/p&gt;
&lt;p&gt;&amp;lt;warning&amp;gt; nrf_sdh_ble: RAM starts at 0x20004190, can be adjusted to 0x20002038.&lt;br /&gt;.&amp;lt;warning&amp;gt; nrf_sdh_ble: RAM size can be adjusted to 0xDFC8.&lt;br /&gt;.&amp;lt;info&amp;gt; app: Multilink example started.&lt;br /&gt;.&amp;lt;info&amp;gt; app: Start scanning for device name Nordic_Blinky.&lt;br /&gt;.&amp;lt;info&amp;gt; app: Connection 0x0 established, starting DB discovery&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Please suggest me, i am new to this. thank you in advance&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mismatch between connection handles in ble_nus?</title><link>https://devzone.nordicsemi.com/thread/123572?ContentTypeID=1</link><pubDate>Fri, 09 Mar 2018 09:02:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e40357e-0899-40ba-badb-ee7846e2602c</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Kashinath,&lt;/p&gt;
&lt;p&gt;You are running into the&amp;nbsp;APP_ERROR_CHECK(err_code) on line 217 in main.c. You should check what function returned this &lt;span&gt;err_code&lt;/span&gt;(often the function right above the APP_ERROR_CHECK), and why it returned NRF_ERROR_INVALID_STATE. If you have more questions about this, you should&lt;a href="https://devzone.nordicsemi.com/support/add"&gt; create your own question here at Devzone&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mismatch between connection handles in ble_nus?</title><link>https://devzone.nordicsemi.com/thread/123437?ContentTypeID=1</link><pubDate>Thu, 08 Mar 2018 12:51:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18ee4782-3091-4c43-b4b0-4c326c9ab672</guid><dc:creator>Kashinath</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;by referring this above, I am using the multilink central example for NUS_C, i changed the code by combining the multilink central and BLE_APP_UART central, i am trying to print the data, but i am not able to print data and also i am getting error after disconnecting all the peripheral.. please suggest me to resolve this issue&lt;/p&gt;
&lt;p&gt;I am getting error like this&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Nordic_Blinky.&lt;br /&gt;.&amp;lt;info&amp;gt; app: Connection 0x1 established, starting DB discovery.&lt;br /&gt;.&amp;lt;info&amp;gt; app: NUS central link 0x1 disconnected (reason: 0x8)&lt;br /&gt;.&amp;lt;info&amp;gt; app: Start scanning for device name Nordic_Blinky.&lt;br /&gt;.&amp;lt;info&amp;gt; app: Connection 0x1 established, starting DB discovery.&lt;br /&gt;.&amp;lt;info&amp;gt; app: NUS central link 0x1 disconnected (reason: 0x8)&lt;br /&gt;.&amp;lt;info&amp;gt; app: Start scanning for device name Nordic_Blinky.&lt;br /&gt;.&amp;lt;info&amp;gt; app: Connection 0x1 established, starting DB discovery.&lt;br /&gt;.&amp;lt;info&amp;gt; app: NUS central link 0x1 disconnected (reason: 0x8)&lt;br /&gt;.&amp;lt;info&amp;gt; app: Start scanning for device name Nordic_Blinky.&lt;br /&gt;.&amp;lt;info&amp;gt; app: NUS central link 0x0 disconnected (reason: 0x8)&lt;br /&gt;.&amp;lt;info&amp;gt; app: Start scanning for device name Nordic_Blinky.&lt;br /&gt;.&amp;lt;error&amp;gt; app: ERROR 8 [NRF_ERROR_INVALID_STATE] at D:\Printer_software\New Folder\nRF5_SDK_14.2.0_17b948a\nRF5_SDK_14.2.0_17b948a\examples\ble_central\ble_app_multilink_central -working\main.c:217&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mismatch between connection handles in ble_nus?</title><link>https://devzone.nordicsemi.com/thread/72614?ContentTypeID=1</link><pubDate>Sun, 08 Jan 2017 10:40:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:157113f0-d558-4695-a04b-f275bb18c6a3</guid><dc:creator>Boaz</dc:creator><description>&lt;p&gt;Thanks Sigurd, that is basically the code I ended up with.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Mismatch between connection handles in ble_nus?</title><link>https://devzone.nordicsemi.com/thread/72613?ContentTypeID=1</link><pubDate>Fri, 06 Jan 2017 15:26:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3241c108-eb53-4c6b-bb31-56ee6dea4c8f</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, the &lt;code&gt;on_hvx()&lt;/code&gt; is not setting the conn_handle for the &lt;code&gt;BLE_NUS_C_EVT_NUS_RX_EVT&lt;/code&gt; event, but you have access to the conn_handle in the &lt;code&gt;p_ble_nus_c&lt;/code&gt; struct. Ideally it should also be set for the &lt;code&gt;ble_nus_c_evt&lt;/code&gt;, i.e. &lt;code&gt;ble_nus_c_evt.conn_handle = p_ble_nus_c-&amp;gt;conn_handle;&lt;/code&gt; in &lt;code&gt;on_hvx()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When the nus_c service was initially designed, the nRF5 series only had support for &lt;em&gt;one&lt;/em&gt; connection. Later the code was refactored and &lt;code&gt;ble_nus_c_handles_assign()&lt;/code&gt; was added so we can keep track of what connection belongs to what instance of NUS.&lt;/p&gt;
&lt;p&gt;So if the overall goal is to use the nus_c service in multiple connections, I recommend that you create a separate NUS and DB structure instance for each connection:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static ble_nus_c_t              m_ble_nus_c[TOTAL_LINK_COUNT];
static uint8_t                  m_ble_nus_c_count;  
static ble_db_discovery_t       m_ble_db_discovery[TOTAL_LINK_COUNT];
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then each instance of NUS would have to be assigned a connection handle with &lt;code&gt;ble_nus_c_handles_assign()&lt;/code&gt; when you get the event &lt;code&gt;BLE_NUS_C_EVT_DISCOVERY_COMPLETE&lt;/code&gt;.
In &lt;code&gt;nus_c_init()&lt;/code&gt; and &lt;code&gt;db_discovery_init()&lt;/code&gt; you will need to initialize each instance. In &lt;code&gt;nus_c_init()&lt;/code&gt; this could look something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void nus_c_init(void)
{
    uint32_t         err_code;
    ble_nus_c_init_t nus_c_init_t;

    nus_c_init_t.evt_handler = ble_nus_c_evt_handler;
    
	for (m_ble_nus_c_count = 0; m_ble_nus_c_count &amp;lt; TOTAL_LINK_COUNT; m_ble_nus_c_count++)
    {
        err_code = ble_nus_c_init(&amp;amp;m_ble_nus_c[m_ble_nus_c_count], &amp;amp;nus_c_init_t);
        APP_ERROR_CHECK(err_code);
    }
    m_ble_nus_c_count = 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;db_disc_handler()&lt;/code&gt; function would look something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void db_disc_handler(ble_db_discovery_evt_t * p_evt)
{
    ble_nus_c_on_db_disc_evt(&amp;amp;m_ble_nus_c[p_evt-&amp;gt;conn_handle], p_evt);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In &lt;code&gt;ble_evt_dispatch()&lt;/code&gt;, &lt;code&gt;ble_db_discovery_on_ble_evt()&lt;/code&gt; and &lt;code&gt;ble_nus_c_on_ble_evt()&lt;/code&gt; should be changed to something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint16_t conn_handle;
conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;

ble_db_discovery_on_ble_evt(&amp;amp;m_ble_db_discovery[conn_handle], p_ble_evt);
ble_nus_c_on_ble_evt(&amp;amp;m_ble_nus_c[conn_handle],p_ble_evt);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You should also take a look at the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.2.0/ble_sdk_app_multilink.html?cp=4_0_1_4_2_0_1"&gt;multilink central example&lt;/a&gt; in the SDK to see how this example handles multiple connections.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>