<?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>Notification write (response) lost when bonding</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/22670/notification-write-response-lost-when-bonding</link><description>This week I worked myself to a series of what seemed to be problems boiling down to one issue:
The Notification Write Response is lost when bonding has to happen first. 
 I&amp;#39;ll try to illustrate this in more detail: 
 
 custom service, derived from</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 09 Jun 2017 14:30:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/22670/notification-write-response-lost-when-bonding" /><item><title>RE: Notification write (response) lost when bonding</title><link>https://devzone.nordicsemi.com/thread/89131?ContentTypeID=1</link><pubDate>Fri, 09 Jun 2017 14:30:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1424f47f-4ac5-480c-9141-6bb88082ef48</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;This is indeed the intended way for this to work. When you send a write request, you will get a write response with a GATT status. Anything else than &amp;quot;Success&amp;quot; means that the write failed. When you set up the characteristics with &lt;code&gt;BLE_GAP_CONN_SEC_MODE_SET_ENC_*&lt;/code&gt;, you are actually setting access restrictions on the characteristic. This means that it is disallowed to write to the characteristic when the GAP security mode is less than the requirement. So your first write request will get a GATT status that says &amp;quot;Insufficient Authentication&amp;quot;.&lt;/p&gt;
&lt;p&gt;It is possible to avoid this in a few ways:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;You can send a security request from your device immediately upon connection. This should trigger a pairing as normal, and if it happens before the write request, it will not end up being lost.&lt;/li&gt;
&lt;li&gt;You can decide to not security protect the attribute, but enable write authorization on it instead. Whenever someone tries to write to it, you will be allowed to make a call whether the write should go through, or if an error code should be returned. If you also choose to store the characteristic in user-space (&lt;code&gt;VLOC_USER&lt;/code&gt;), you will be able to see the data in the request and manually set it for later.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In any case, you should assume that a write request can fail, so harden your application to handle it. The way the SoftDevice is handling this is the default behavior of Bluetooth.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>