<?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>When has the Central has written to a peripheral?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/82017/when-has-the-central-has-written-to-a-peripheral</link><description>My application is a Central using SD140. 
 The connection to the peripheral is made successfully. What event will I get when the Central successfully writes to the connected Peripheral&amp;#39;s characteristic? 
 And will there be an event if the Write does not</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 29 Nov 2021 10:37:39 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/82017/when-has-the-central-has-written-to-a-peripheral" /><item><title>RE: When has the Central has written to a peripheral?</title><link>https://devzone.nordicsemi.com/thread/341039?ContentTypeID=1</link><pubDate>Mon, 29 Nov 2021 10:37:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:297cff90-dc06-409f-b353-9f7f3b2ef719</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;in the similar way you need to check the gatt_status and based on it handle it to see if you need to give up write operation or retry it after sometime.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: When has the Central has written to a peripheral?</title><link>https://devzone.nordicsemi.com/thread/341037?ContentTypeID=1</link><pubDate>Mon, 29 Nov 2021 10:36:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0791b9f5-7a70-4e35-ab69-183e10eddf70</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;one example could be to check for what kind of status you get. There could be many status including the rejection of write operation due to auth settings etc.&lt;/p&gt;
&lt;p&gt;For example you can use this code snippet to check to see if you got a response that the write is rejected due to authentication.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void on_write_rsp(ble_hrs_c_t * p_ble_hrs_c, const ble_evt_t * p_ble_evt)
{
    // Check if the event if on the link for this instance
    if (p_ble_hrs_c-&amp;gt;conn_handle != p_ble_evt-&amp;gt;evt.gattc_evt.conn_handle)
    {
        return;
    }

    if ((p_ble_evt-&amp;gt;evt.gattc_evt.gatt_status == BLE_GATT_STATUS_ATTERR_INSUF_AUTHENTICATION) ||
        (p_ble_evt-&amp;gt;evt.gattc_evt.gatt_status == BLE_GATT_STATUS_ATTERR_INSUF_ENCRYPTION))
    {
         // write req rejected most likely due to AUTH setup delays, retry until AUTH setup is complete
         // wait until encryption is complete and retry write operation.

    }
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;and handle the write response from the peer in the&amp;nbsp;ble_hrs_c_on_ble_evt as below&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;        case BLE_GATTC_EVT_WRITE_RSP:
            on_write_rsp(p_ble_hrs_c, p_ble_evt);
            break;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: When has the Central has written to a peripheral?</title><link>https://devzone.nordicsemi.com/thread/340551?ContentTypeID=1</link><pubDate>Wed, 24 Nov 2021 13:21:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f48150ff-ed05-4fa0-8642-8227f2802505</guid><dc:creator>DanPhelan</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;/p&gt;
&lt;p&gt;Do you have an example of handling the Write errors and Timeout cases?&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Dan&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; case BLE_GATTC_EVT_WRITE_RSP:&lt;br /&gt; {&lt;br /&gt; if ((BLE_GATT_STATUS_SUCCESS != p&lt;strong&gt;_ble_evt-&amp;gt;evt.gattc_evt.gatt_status))&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; {&lt;/strong&gt;&lt;br /&gt; // Handle retry of the write depending upon the error&lt;/p&gt;
&lt;p&gt;// What element in the structure would hold the errors?&lt;br /&gt; }else{// success ...&lt;br /&gt; const ble_gattc_evt_write_rsp_t * p_val = &amp;amp;p_ble_evt-&amp;gt;evt.gattc_evt.params.write_rsp;&lt;br /&gt; // handles moving to the next step when the write has completed. &lt;br /&gt; cble_nus_c_handleWriteChar(p_val);&lt;br /&gt; }&lt;br /&gt; }&lt;br /&gt; break;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;case BLE_GATTC_EVT_TIMEOUT:&lt;br /&gt; // Disconnect on GATT Client timeout event.&lt;br /&gt; NRF_LOG_DEBUG(&amp;quot;GATT Client Timeout.&amp;quot;);&lt;br /&gt; &lt;br /&gt; // Put a retry here instead?&lt;br /&gt; err_code = sd_ble_gap_disconnect(p_ble_evt-&amp;gt;evt.gattc_evt.conn_handle,&lt;br /&gt; BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;br /&gt; break;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: When has the Central has written to a peripheral?</title><link>https://devzone.nordicsemi.com/thread/340484?ContentTypeID=1</link><pubDate>Wed, 24 Nov 2021 09:52:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3caf6297-5a23-4ebc-90e7-6520f02583d9</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user=""] What event will I get when the Central successfully writes to the connected Peripheral&amp;#39;s characteristic?[/quote]
&lt;p&gt;Using a write request&amp;nbsp;BLE_GATT_OP_WRITE_REQ to write to the characteristic will give you&amp;nbsp;&lt;span&gt;BLE_GATTC_EVT_WRITE_RSP to the client (client device that is writing to the characteristic on the server).&lt;/span&gt;&lt;/p&gt;
[quote user=""]And will there be an event if the Write does not complete?[/quote]
&lt;p&gt;&lt;span&gt;Then you should get an error in that event if some permissions or state was not valid or you will get a procedural timeout if the operation was not completed for other reasons.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>