<?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>delayed disconnect with  sd_ble_gap_disconnect()?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/26355/delayed-disconnect-with-sd_ble_gap_disconnect</link><description>Hello, 
 Are there any conditions where the sd_ble_gap_disconnect() will not immediately terminate the link? 
 My Setup: Nrf52, SDK 13.0.0, own board, based from HRM code(exteeeensive modification). 
 On initial bootup, I fast advertise. Once I get</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 20 Jun 2018 13:15:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/26355/delayed-disconnect-with-sd_ble_gap_disconnect" /><item><title>RE: delayed disconnect with  sd_ble_gap_disconnect()?</title><link>https://devzone.nordicsemi.com/thread/136919?ContentTypeID=1</link><pubDate>Wed, 20 Jun 2018 13:15:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9be040a2-caa4-4ea2-918e-58bd32bed140</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Ben,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Great to&amp;nbsp;get back after 8 months :)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think I know what&amp;#39;s wrong here. What kind of central device do you have ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Disconnect event 0x22 means&amp;nbsp;BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT. This happens when the central stopped communication for too long end the connection terminated because of the timeout. So when the peripheral send connection terminate request ( because of&amp;nbsp;sd_ble_gap_disconnect() ) it would expect an ACK from the central before it actually stop the connection and throw&amp;nbsp;BLE_GAP_EVT_DISCONNECTED event back to the application.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But in this case, it seemed that the central stopped immediately after it receive the connection terminate request. It forgot to send the last ACK packet back to the peripheral. This results in the peripheral kept waiting for that ACK until timeout.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;(Or it could be that the last ACK was lost and the peripheral never receive it, and there is no retransmission, of course)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: delayed disconnect with  sd_ble_gap_disconnect()?</title><link>https://devzone.nordicsemi.com/thread/136828?ContentTypeID=1</link><pubDate>Wed, 20 Jun 2018 05:05:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1a92bf8-b524-40c3-9121-a26c44e1807b</guid><dc:creator>benkokes</dc:creator><description>&lt;p&gt;HI Hung,&lt;/p&gt;
&lt;p&gt;Yes, I have the line &lt;code&gt;m_conn_handle = BLE_CONN_HANDLE_INVALID; inside BLE_GAP_EVT_DISCONNECTED event handler inside on_ble_evt().&amp;nbsp; (I don&amp;#39;t have a function explicitly named ble_evt_handler().)&amp;nbsp;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;so if I call sd_ble_gap_disconnect() then immediately printout the value of m_conn_handle, I see that it has a value ( of 0, verifying its not 0xFFFF).&lt;/p&gt;
&lt;p&gt;Putting in a few more checks, I see I hit the BLE_GAP_EVT_DISCONNECTED in about 4 seconds. The disconnect reason is a 34 (0x22). I check the value of m_conn_handle after that, and its the expected value of 0xFFFF.&lt;/p&gt;
&lt;p&gt;Could there possibly be some sort of negotiation going on between the peripheral and central? Maybe I am not sending some expected parameters OR maybe I am missing some sort of disconnect data from the central?&lt;/p&gt;
&lt;p&gt;Is there some way to see if the softdevice is waiting on some response from the central or maybe there is a timer somewhere that needs handling?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: delayed disconnect with  sd_ble_gap_disconnect()?</title><link>https://devzone.nordicsemi.com/thread/103719?ContentTypeID=1</link><pubDate>Tue, 31 Oct 2017 15:33:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca198c3f-eba1-4e85-a332-fb72c810da7f</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;I don&amp;#39;t really understand it.&lt;/p&gt;
&lt;p&gt;Could you verify that you have the code &lt;code&gt;m_conn_handle = BLE_CONN_HANDLE_INVALID;&lt;/code&gt; inside BLE_GAP_EVT_DISCONNECTED event handler inside ble_evt_handler() ?&lt;/p&gt;
&lt;p&gt;After that command the m_conn_handle should be 0xFFFF. Are you saying the line of code doesn&amp;#39;t have any effect on m_conn_handle?&lt;/p&gt;
&lt;p&gt;If it&amp;#39;s not, then it must be assigned somewhere else, most likely because the central tried to connect again ?&lt;/p&gt;
&lt;p&gt;It&amp;#39;s pretty easy to find how long it would take to get BLE_GAP_EVT_DISCONNECTED event, simply print out some text on UART/RTT when you receive the event, I suggest to also do the same with BLE_GAP_EVT_CONNECTED&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: delayed disconnect with  sd_ble_gap_disconnect()?</title><link>https://devzone.nordicsemi.com/thread/103716?ContentTypeID=1</link><pubDate>Tue, 31 Oct 2017 15:08:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd5085a1-b3b2-4123-aa76-f9a2965c4e27</guid><dc:creator>benkokes</dc:creator><description>&lt;p&gt;Hi Hung,
Sorry, I thought that I answered that question from Martin. Anyhow, Yes, It does hit the BLE_GAP_EVT_DISCONNECTED within on_ble_evt() the second time. As to how &amp;#39;immediate&amp;#39; it is, that is difficult for me to quantify due to not being able to step through the code whilst Softdevice is active ( as you know).  It SEEMS close to immediate, because it happens within 1 second of obtaining time from the server. The disconnect is programmatically planned, so other than setting GPIOs to determine actual timing, I cannot guarantee the timing immediacy. However it does happen soon after the command to disconnect from the central.&lt;/p&gt;
&lt;p&gt;I was counting on the m_conn_handle to be reset to 0xFFFF the second time, but after I get out of the switch statement containing the BLE_GAP_EVT_DISCONNECTED code, my m_conn_handle still is 0x0;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: delayed disconnect with  sd_ble_gap_disconnect()?</title><link>https://devzone.nordicsemi.com/thread/103718?ContentTypeID=1</link><pubDate>Tue, 31 Oct 2017 14:44:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b5eba2f-34dc-406c-a6ed-3cdde0b161de</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Could you please answer my question ?&lt;/p&gt;
&lt;p&gt;&amp;quot;Did you hit BLE_GAP_EVT_DISCONNECTED event, immediately after you call sd_ble_gap_disconnect() ?&amp;quot;&lt;/p&gt;
&lt;p&gt;Note that there is nothing special about m_conn_handle, we simply set m_conn_handle = 0xFFFF when there is a BLE_GAP_EVT_DISCONNECTED event.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: delayed disconnect with  sd_ble_gap_disconnect()?</title><link>https://devzone.nordicsemi.com/thread/103717?ContentTypeID=1</link><pubDate>Tue, 31 Oct 2017 14:41:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:884d57f1-e518-44b3-bb7c-07435631982f</guid><dc:creator>benkokes</dc:creator><description>&lt;p&gt;Hi Hung,&lt;/p&gt;
&lt;p&gt;fortunately, I do not perform the blocking loop within the on_ble_evt() function, BUT it still blocks elsewhere in the code, waiting for the handle to be 0xFFFF.  My suspicion now is that Martin is on to something, where the immediate re-advertising/reconnect happens. Getting a sequence is difficult, since I cannot step through the code at that point...Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: delayed disconnect with  sd_ble_gap_disconnect()?</title><link>https://devzone.nordicsemi.com/thread/103715?ContentTypeID=1</link><pubDate>Tue, 31 Oct 2017 11:24:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c055e04-a7c5-4370-9f2b-d8786b0c9c13</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Benkokes,&lt;/p&gt;
&lt;p&gt;Did you hit BLE_GAP_EVT_DISCONNECTED event, immediately after you call sd_ble_gap_disconnect() ? If you want to check if the connection is terminated or not, you should wait for that event, not waiting for m_conn_handle to be = 0xFFFF. Please try not to stay in a loop to check for m_conn_handle, if you do that in an event handler, you are blocking other event to come. Results in infinite loop.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: delayed disconnect with  sd_ble_gap_disconnect()?</title><link>https://devzone.nordicsemi.com/thread/103714?ContentTypeID=1</link><pubDate>Sun, 29 Oct 2017 22:16:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27227b60-f721-466d-a21d-d9785a5bc9b5</guid><dc:creator>benkokes</dc:creator><description>&lt;p&gt;Hi Martin,
Yes, it hits the BLE_GAP_EVT_DISCONNECTED every time.  My central device is running a CTS server whose sole purpose is to serve time. I constantly wait for connections and give time to the peripheral once asked. I would rather not edit the on_disconnected() function in ble_advertising.c if there might be another solution...
Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: delayed disconnect with  sd_ble_gap_disconnect()?</title><link>https://devzone.nordicsemi.com/thread/103713?ContentTypeID=1</link><pubDate>Fri, 27 Oct 2017 08:55:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:974ffbb2-7cd5-4b96-8a84-f289e597a6e9</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;I wasn&amp;#39;t able to reproduce this. Have you set a breakpoint in the BLE_GAP_EVT_DISCONNECTED event to confirm that the disconnect event itself is not happening? Is it possible that your peer device is immediately trying to reconnect after the second disconnect?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>