<?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>Cannot disconnect the device once it is connected</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/28512/cannot-disconnect-the-device-once-it-is-connected</link><description>Hello guys, 
 I have problem, I activate the BLE and connect it to my tablet application until then nothing wrong happens. But when I use sd_ble_gap_disconnect() to disconnect, I got error_code 0x3002 which prevent me to disconnect. 
 what I do to disconnect</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 21 Dec 2017 15:35:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/28512/cannot-disconnect-the-device-once-it-is-connected" /><item><title>RE: Cannot disconnect the device once it is connected</title><link>https://devzone.nordicsemi.com/thread/112850?ContentTypeID=1</link><pubDate>Thu, 21 Dec 2017 15:35:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1237afe-33e8-4c04-852f-eb825b8119d7</guid><dc:creator>Kyle Krueger</dc:creator><description>&lt;p&gt;Only modifying it on disconnect could also be a problem. It should be modified on connect to update it. This way, in the case you make a connection, lose it, reestablish the connect, and try to end it manually, it may no longer have the correct handle.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot disconnect the device once it is connected</title><link>https://devzone.nordicsemi.com/thread/112848?ContentTypeID=1</link><pubDate>Thu, 14 Dec 2017 08:40:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61df3fc8-70e2-4efd-bbfb-08de8e5818b9</guid><dc:creator>Joakim Jakobsen</dc:creator><description>&lt;p&gt;Hard to say why it won&amp;#39;t disconnect. Maybe you could upload your project so I can test it here?&lt;br /&gt;
Best regards.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot disconnect the device once it is connected</title><link>https://devzone.nordicsemi.com/thread/112847?ContentTypeID=1</link><pubDate>Mon, 11 Dec 2017 15:59:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12f43a09-680f-4826-9b4c-9582251b26f6</guid><dc:creator>soma</dc:creator><description>&lt;p&gt;I&amp;#39;m working with the SDK 11.
I&amp;#39;m launching the disconnecting related code when I receive the event of a press button.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot disconnect the device once it is connected</title><link>https://devzone.nordicsemi.com/thread/112846?ContentTypeID=1</link><pubDate>Tue, 05 Dec 2017 13:58:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0e96047-978d-4c39-ae70-94d8b6f001c1</guid><dc:creator>Joakim Jakobsen</dc:creator><description>&lt;p&gt;Which SDK example are you working with?&lt;br /&gt;
When do you make the call to the sd_ble_gap_disconnect()? Is it on a specific event that you want to disconnect?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot disconnect the device once it is connected</title><link>https://devzone.nordicsemi.com/thread/112845?ContentTypeID=1</link><pubDate>Tue, 05 Dec 2017 13:50:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67251194-768c-43b6-9960-40f3a98951c3</guid><dc:creator>soma</dc:creator><description>&lt;p&gt;yeah i&amp;#39;m sure that the device is connected. I even tried with the nrf toolbox and nrf connect application.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot disconnect the device once it is connected</title><link>https://devzone.nordicsemi.com/thread/112844?ContentTypeID=1</link><pubDate>Tue, 05 Dec 2017 11:22:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9dbbfae3-04bb-4145-85d2-df6f5178dd64</guid><dc:creator>Joakim Jakobsen</dc:creator><description>&lt;p&gt;Hi Soma!&lt;/p&gt;
&lt;p&gt;Are you sure that you are in a connection and that the connection handle has been updated before
initiating the disconnect?&lt;br /&gt;
The error 0x3002 indicates that a &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v2.0.0/group__ble__err.html#gabdc27cbc2ffac4a50640a0ce992c03af"&gt;invalid connection handle&lt;/a&gt; has been supplied.&lt;br /&gt;
I tested this in the ble_app_uart example in SDK 11, and it seems to work fine.&lt;br /&gt;
I executed the disconnection on a button push;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;bool check; 
uint32_t err_code;
	case BSP_EVENT_KEY_2: 
	   check = softdevice_handler_isEnabled();
	   if ((check == true) &amp;amp;&amp;amp; (m_conn_handle != BLE_CONN_HANDLE_INVALID))
	   {
	      err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
	      APP_ERROR_CHECK(err_code);
	   }
	   break; 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v2.0.0/group___b_l_e___g_a_p___f_u_n_c_t_i_o_n_s.html#ga4031d0e4034c6f5900ad6d35b763fb0d"&gt;sd_ble_gap_disconnect()&lt;/a&gt; call initiates the disconnection procedure, and its completion
will be communicated to the application with a BLE_GAP_EVT_DISCONNECTED event.
Your connection handle will most likely be set to invalid when the disconnection event is received.&lt;br /&gt;
Take a look at this &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s132.api.v2.0.0%2Fgroup___b_l_e___g_a_p___c_o_n_n___m_s_c.html"&gt;message sequence chart&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;When the disconnection event i received, the device will most likely start advertising again.&lt;br /&gt;
You can see how this is handled in the &lt;code&gt;ble_advertising.c&lt;/code&gt; file.&lt;br /&gt;
The fact that the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v2.0.0/group___b_l_e___g_a_p___f_u_n_c_t_i_o_n_s.html#gaa88eea8e9e95dd96a7633e2c62f3ce16"&gt;sd_ble_gap_adv_stop()&lt;/a&gt; returns error code 0x0008 (&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v2.0.0/group__nrf__error.html#gaf0aff2ba7864b34a36b4a96986e1851e"&gt;NRF_ERROR_INVALID_STATE&lt;/a&gt;)
is most probably because your device is not in advertising state yet.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;
Joakim.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot disconnect the device once it is connected</title><link>https://devzone.nordicsemi.com/thread/112840?ContentTypeID=1</link><pubDate>Tue, 05 Dec 2017 09:05:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b037bd0-87ec-41be-bb7e-198851a35e05</guid><dc:creator>soma</dc:creator><description>&lt;p&gt;Hi
I use the SDK 11.0&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot disconnect the device once it is connected</title><link>https://devzone.nordicsemi.com/thread/112841?ContentTypeID=1</link><pubDate>Tue, 05 Dec 2017 08:38:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52fb7b4b-e3ec-4c18-891c-5d84b9ba0e63</guid><dc:creator>Joakim Jakobsen</dc:creator><description>&lt;p&gt;Hi Soma!&lt;br /&gt;
Which SDK are you working with?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot disconnect the device once it is connected</title><link>https://devzone.nordicsemi.com/thread/112849?ContentTypeID=1</link><pubDate>Mon, 04 Dec 2017 08:32:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ffc2ac2-6ff1-4ff3-b021-d87ff57291a1</guid><dc:creator>soma</dc:creator><description>&lt;p&gt;i tried doing it adding brackets to my statement but nothing changed.
And I also tried to trace the modification of m_conn_handle but I only modify it after being disconnected&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void on_disconnect(ble_evt_t * p_ble_evt)
{
    uint32_t err_code;

    m_conn_handle = BLE_CONN_HANDLE_INVALID;

    // Stop timer if running
    m_update_count = 0; // Connection parameters updates should happen during every connection

    err_code = app_timer_stop(m_conn_params_timer_id);
    if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp; (m_conn_params_config.error_handler != NULL))
    {
        m_conn_params_config.error_handler(err_code);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;here is the code where it is modifed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot disconnect the device once it is connected</title><link>https://devzone.nordicsemi.com/thread/112843?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 19:49:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef236aae-de25-4cf1-afe0-4287e3a1014f</guid><dc:creator>Kyle Krueger</dc:creator><description>&lt;p&gt;Maybe &lt;a href="https://devzone.nordicsemi.com/question/13468/when-i-use-sd_ble_gap_disconnect-in-button-evt-handle-it-appear-error_code-0x3002/?answer=17924#post-id-17924"&gt;this question&lt;/a&gt; could also be helpful&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot disconnect the device once it is connected</title><link>https://devzone.nordicsemi.com/thread/112842?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 18:57:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb845e2d-5146-4aee-ba82-29b1e84b2214</guid><dc:creator>Kyle Krueger</dc:creator><description>&lt;p&gt;Error 0x3002  means &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v5.0.0/group__ble__err.html#gabdc27cbc2ffac4a50640a0ce992c03af"&gt;BLE_ERROR_INVALID_CONN_HANDLE&lt;/a&gt;, so it sounds like your validity check on m_conn_handle isn&amp;#39;t working.&lt;/p&gt;
&lt;p&gt;That makes the if statement suspect. I&amp;#39;d first recommend adding brackets to your if statement to separate the two logical comparisons.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;if ((check == true) &amp;amp;&amp;amp; (m_conn_handle != BLE_CONN_HANDLE_INVALID))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This makes sure the compiler knows the order to make the comparison in.&lt;/p&gt;
&lt;p&gt;If that doesn&amp;#39;t help, follow up on where m_conn_handle is last written, and post it here. Note that m_conn_handle can be invalid when it has other values than BLE_CONN_HANDLE_INVALID.&lt;/p&gt;
&lt;p&gt;For example, the connection has already been once broken due to a poor signal, and m_conn_handle was not updated.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>