<?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>Disconnecting after sending read response</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/8917/disconnecting-after-sending-read-response</link><description>I have a project where specification requires disconnecting immediately after sending a response to a BLE read request. I&amp;#39;m using authorized reads. 
 Currently, I&amp;#39;m using sd_ble_gatts_rw_authorize_reply to send the read response, and then follow with</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 31 Aug 2015 09:28:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/8917/disconnecting-after-sending-read-response" /><item><title>RE: Disconnecting after sending read response</title><link>https://devzone.nordicsemi.com/thread/32817?ContentTypeID=1</link><pubDate>Mon, 31 Aug 2015 09:28:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45088839-c965-4b75-bea1-af46c248c6dc</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Etan,
You are welcome. If you are OK with the answer, please mark it as correct so we can close the case :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disconnecting after sending read response</title><link>https://devzone.nordicsemi.com/thread/32816?ContentTypeID=1</link><pubDate>Sat, 29 Aug 2015 10:59:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:251ee97f-8d1d-48cf-a174-4f50835db0a3</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;First workaround sounds okay - second one looks a bit hackish ^^ Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disconnecting after sending read response</title><link>https://devzone.nordicsemi.com/thread/32815?ContentTypeID=1</link><pubDate>Thu, 27 Aug 2015 12:13:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5d2ce0c5-1472-441f-9249-10ba0810e801</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;@Etan: If you can&amp;#39;t send another write request, you can think of using a timer to disconnect after few connection interval. This won&amp;#39;t guarantee that the write response has been received. But if you set the timer time out larger than the connection timeout, then you can be sure, it will be either the write response has been received (then disconnect), or the connection will be timed out.&lt;/p&gt;
&lt;p&gt;Another option is to queue several (more than 7th) notification on the peripheral until it&amp;#39;s full, if you can add more notification after it&amp;#39;s full, you can safely disconnect, because you can only send more notification when the write response is finished.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disconnecting after sending read response</title><link>https://devzone.nordicsemi.com/thread/32814?ContentTypeID=1</link><pubDate>Thu, 27 Aug 2015 12:04:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0126a455-2f6f-4a32-adf2-fb50ab11c77e</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;But thanks for the suggestions! &amp;lt;3 You guys are awesome for the fast support you provide!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disconnecting after sending read response</title><link>https://devzone.nordicsemi.com/thread/32813?ContentTypeID=1</link><pubDate>Thu, 27 Aug 2015 12:03:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9767ab9c-d5ac-4052-bfbe-b888b62b21db</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;Unfortunately, I don&amp;#39;t have control over the central. So I cannot change the way the protocol works.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disconnecting after sending read response</title><link>https://devzone.nordicsemi.com/thread/32812?ContentTypeID=1</link><pubDate>Thu, 27 Aug 2015 12:01:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b4f42db-620c-4caa-bcd7-70007cb2ec9e</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Etan,&lt;/p&gt;
&lt;p&gt;I think it makes sense on what you have observed. When calling sd_ble_gatts_rw_authorize_reply() returns NRC_SUCCESS , it only means the reply is queued.
It queued and prepared to be sent in the next connection event.
However, you call sd_ble_gap_disconnect() right after that. This call won&amp;#39;t wait untill both the application buffer and stack internal buffer are free before sending the connection terminate command. It will be executed in the next event. So what queued in the buffer(s) will be discarded.&lt;/p&gt;
&lt;p&gt;My suggestion for you is to do write request 2 times. So that when you got the first write request, you reply and then set a flag. On the client, when you have the reply, and want to disconnect, you send another write request.
On the server, when receive the second write request, and if the flag is set, you can simply disconnect.
The reason we do this because, with BLE protocol, only one write request can be performed at a time. When the first one is not done, write response successfully received, the next write request won&amp;#39;t be executed.&lt;/p&gt;
&lt;p&gt;By waiting for the next write request, we can be sure the first one have been replied and can disconnect, without replying to the second write request.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disconnecting after sending read response</title><link>https://devzone.nordicsemi.com/thread/32811?ContentTypeID=1</link><pubDate>Wed, 26 Aug 2015 18:33:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a3bc076-7e38-4982-8d91-123064cd3836</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;I call sd_ble_gatts_rw_authorize_reply with NRF_SUCCESS. The response is properly queued up if I remove the disconnect call.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disconnecting after sending read response</title><link>https://devzone.nordicsemi.com/thread/32810?ContentTypeID=1</link><pubDate>Wed, 26 Aug 2015 13:10:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19a24219-0b24-4711-9bed-72d25ae9bc6e</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;Maybe some more generic events, like the &amp;quot;Number of Completed Packets&amp;quot; event could help? I know that there&amp;#39;s no documented event for what I want, but maybe there&amp;#39;s a trick to achieve my goal.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disconnecting after sending read response</title><link>https://devzone.nordicsemi.com/thread/32809?ContentTypeID=1</link><pubDate>Wed, 26 Aug 2015 13:10:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:262ee605-ce9e-460f-929e-428aae57ebce</guid><dc:creator>Michael Dietz</dc:creator><description>&lt;p&gt;where response is queued upon app returning NRF_SUCCESS - which seems to be where your problem arises.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disconnecting after sending read response</title><link>https://devzone.nordicsemi.com/thread/32808?ContentTypeID=1</link><pubDate>Wed, 26 Aug 2015 13:08:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb2b8638-2d4c-4512-88a5-25616326ea19</guid><dc:creator>Michael Dietz</dc:creator><description>&lt;p&gt;Quick answer: based on this message sequence chart it doesn&amp;#39;t look like there are any events being generated after the reply has been sent to the central.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/gatts_5F00_read_5F00_request_5F00_with_5F00_authorization.png"&gt;gatts_read_request_with_authorization.png&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Maybe someone else can help though.&lt;/p&gt;
&lt;p&gt;-Mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>