<?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>Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/12410/long-write-only-writes-4-packets</link><description>Hello, 
 I&amp;#39;m implementing long write function to my project. 
 I managed to get it working, but i can&amp;#39;t send more than 68 bytes of data.
When i&amp;#39;m sending the data, I slice it into &amp;lt;18bytes chunks and send each chunk with correct offset, using &amp;quot;BLE_GATT_OP_PREP_WRITE_REQ</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 09 Mar 2016 15:47:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/12410/long-write-only-writes-4-packets" /><item><title>RE: Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/thread/46951?ContentTypeID=1</link><pubDate>Wed, 09 Mar 2016 15:47:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e2d4dc6-c8ec-44bb-b854-0f6a9f1892ab</guid><dc:creator>nejcokle</dc:creator><description>&lt;p&gt;There, now it works perfectly! I handle BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL by sending execute like you said, and then continue sending packets.
Thanks for your help.
Best regards,
Nejc&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/thread/46950?ContentTypeID=1</link><pubDate>Wed, 09 Mar 2016 14:45:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5ea5ca3-7923-4f18-9d3c-740fb4dd4a3c</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;Okay, then we&amp;#39;re a bit closer at least. You need to verify that the buffer has enough space in it, and that you report this correctly in the memory request. Alternatively, you can send an execute when you get a &lt;code&gt;BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL&lt;/code&gt;, then continue sending more packets from where you left off.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/thread/46949?ContentTypeID=1</link><pubDate>Wed, 09 Mar 2016 14:35:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:368e1c65-c8d3-4671-82dd-60ebcbb0a3c7</guid><dc:creator>nejcokle</dc:creator><description>&lt;p&gt;Ah yes, i was only watching of my event handle returned NRF_SUCCESS, not the status. I thought that since i get right write event, i don&amp;#39;t have gatt_status errors. But yeah, you were right all along, sorry we had to go such a long way :).&lt;/p&gt;
&lt;p&gt;After debugging i found out that i DO get &amp;quot;BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL&amp;quot; after 4 packets.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/thread/46948?ContentTypeID=1</link><pubDate>Wed, 09 Mar 2016 13:27:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:62d190e9-272e-4504-9769-200eb6166474</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;I see that I have misunderstood you a bit then. Yes, it is possible to use e.g. authorization to receive data written to a characteristic, and then manually writing it to an offset with &lt;code&gt;sd_ble_gatts_value_set&lt;/code&gt;, but you would need to keep track of the offset and make sure the data goes to the correct place.&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s go back to the original issue at hand. Can you confirm that you send a prepare write request, the &lt;code&gt;sd_ble_gattc_write&lt;/code&gt; call returns NRF_SUCCESS, and that you receive a &lt;code&gt;BLE_GATTC_EVT_WRITE_RSP&lt;/code&gt; for each packet you send? And the evt-&amp;gt;gattc_evt.gatt_status of all those events are &lt;code&gt;BLE_GATT_STATUS_SUCCESS&lt;/code&gt;?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/thread/46947?ContentTypeID=1</link><pubDate>Wed, 09 Mar 2016 12:43:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d08022ae-efbb-408e-87c7-eda26d7afbdb</guid><dc:creator>nejcokle</dc:creator><description>&lt;p&gt;Yes i normally used &amp;quot;BLE_GATT_OP_WRITE_REQ&amp;quot;, but wanted to implement Long Writes. Since i can&amp;#39;t use offsets with &amp;quot;BLE_GATT_OP_WRITE_REQ&amp;quot;, do i have to handle char value update on my own? I mean, do i need to just send packets with my data, and when it&amp;#39;s all through merge packets with offsets by 20 and manually update my characteristic value?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/thread/46946?ContentTypeID=1</link><pubDate>Wed, 09 Mar 2016 11:50:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:88321953-3f48-420c-9bf5-29b501b2a418</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;You can use &lt;code&gt;BLE_GATT_OP_WRITE_REQ&lt;/code&gt; or &lt;code&gt;BLE_GATT_OP_WRITE_CMD&lt;/code&gt;. Write requests are limited the same way as prepare write requests, in that you have to wait for a response before you can send the next one. But the response will return with important error codes, like if the characteristic needs security. Write commands can be queued, and depending on your role and the SoftDevice, you can send up to 6 of them per connection interval. So they are much faster than other writes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/thread/46945?ContentTypeID=1</link><pubDate>Tue, 08 Mar 2016 17:29:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:82b68bdd-32f9-4562-83ef-d6454d2faaac</guid><dc:creator>nejcokle</dc:creator><description>&lt;p&gt;Yes, i&amp;#39;ve seen that table. I made a buffer that&amp;#39;s 200 bytes big, and i want to send around 90 - 100 bytes of data, so the buffer should be big enough.
Hmm, never thought about that, but i don&amp;#39;t really need to write multiple characteristics at once..
Which command do i use then if i just want to update one characteristic, and write in it with offsets? Which parameter should i use instead of &amp;quot;BLE_GATT_OP_PREP_WRITE_REQ&amp;quot;?&lt;/p&gt;
&lt;p&gt;Yeah it&amp;#39;s really strange there are no errors... I&amp;#39;ve been working on this problem for a few days now...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/thread/46944?ContentTypeID=1</link><pubDate>Tue, 08 Mar 2016 16:19:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71f9c3ce-55d5-470b-b3c5-33a1bfca3b8e</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;The buffer needs to be big enough to contain all the data packets and their handles. See &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s130.api.v1.0.0%2Fgroup___b_l_e___g_a_t_t_s___q_u_e_u_e_d___w_r_i_t_e_s___u_s_e_r___m_e_m.html&amp;amp;cp=2_7_2_1_1_2_3_1"&gt;this table&lt;/a&gt; to see the layout of each packet. This means that you will have to account for 6 bytes of overhead per Prepare Write Request.&lt;/p&gt;
&lt;p&gt;That is what long writes (also called reliable writes) are about. You queue up a lot of write requests, then write them all at once. If you do not need this functionality, it is better to just send write commands with an offset. The upside of the feature is that you can choose to write to multiple characteristics at the same time, or to keep data consistent at all times.&lt;/p&gt;
&lt;p&gt;It is fairly strange that the write response does not generate any error though.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/thread/46943?ContentTypeID=1</link><pubDate>Tue, 08 Mar 2016 15:43:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8635f834-892b-4f7e-9b36-94350669e821</guid><dc:creator>nejcokle</dc:creator><description>&lt;p&gt;ah sorry, i accidentally marked your comment as answer..
No the sender doesn&amp;#39;t get any errors. I write to reciever and then wait for BLE_GATTC_EVT_WRITE_RSP. Also, the buffer provided for longwrite is a bit bigger than the size of data i want to send.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/thread/46942?ContentTypeID=1</link><pubDate>Tue, 08 Mar 2016 15:07:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2aa2e87f-c3af-47ee-9280-92394700e169</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;Also, it is the sender that will see any errors. When you send a prepare write request, you get a BLE_GATTC_EVT_WRITE_RSP. All the GATTC events have a &amp;quot;gatt_status&amp;quot; flag that contains any error reported by the peer side. In this case, the peer knows that the queue is full, and responds autonomously.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/thread/46941?ContentTypeID=1</link><pubDate>Tue, 08 Mar 2016 15:03:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61823470-eaac-41dd-9d87-717936b832b8</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;Okay, so the receiving side is a Nordic SoftDevice. If you look at &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s130.api.v1.0.0%2Fgroup___b_l_e___g_a_t_t_s___q_u_e_u_e_d___w_r_i_t_e___b_u_f___n_o_a_u_t_h___m_s_c.html"&gt;the MSCs&lt;/a&gt;, you see that you initially get a memory request from the SoftDevice. You reply here with a pointer to a memory block. The size of this block decides how many prepare writes you can store until an execute is needed.&lt;/p&gt;
&lt;p&gt;So you need to increase QUEUED_WRITE_BUFFER_SIZE to fit more into the buffer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/thread/46940?ContentTypeID=1</link><pubDate>Tue, 08 Mar 2016 15:01:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:993f72f3-5aa7-48a8-9e21-0904a5bfa18b</guid><dc:creator>nejcokle</dc:creator><description>&lt;p&gt;When i monitor my terminal, i get:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;MEM REQUEST&lt;/li&gt;
&lt;li&gt;BLE_GATTS_EVT_WRITE&lt;/li&gt;
&lt;li&gt;USER_MEM_RELEASE&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;i do not get any errors&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/thread/46939?ContentTypeID=1</link><pubDate>Tue, 08 Mar 2016 14:58:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64f4e431-3f11-47c0-acde-575b3046c614</guid><dc:creator>nejcokle</dc:creator><description>&lt;p&gt;On a receiving side i handle my long write request like that:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;case BLE_GATTS_EVT_WRITE:
  LOG_INFO(&amp;quot;BLE_GATTS_EVT_WRITE&amp;quot;);
break;
case BLE_EVT_USER_MEM_REQUEST:
LOG_INFO(&amp;quot;MEM REQUEST&amp;quot;);
							
mem_block.len = QUEUED_WRITE_BUFFER_SIZE;
mem_block.p_mem = &amp;amp;queued_write_buffer[0];
							
error_code = sd_ble_user_mem_reply(m_conn_handle, &amp;amp;mem_block);
if (error_code != NRF_SUCCESS) {
LOG_INFO(&amp;quot;ERROR sd_ble_user_mem_reply: %u\r\n&amp;quot;, (unsigned int)error_code);
} else {
  LOG_INFO(&amp;quot;USER_MEM_REQUEST OK\r\n&amp;quot;);
}
break;
case BLE_EVT_USER_MEM_RELEASE:
if ((p_ble_evt-&amp;gt;evt.common_evt.params.user_mem_release.mem_block.p_mem == mem_block.p_mem)&amp;amp;&amp;amp;(p_ble_evt-&amp;gt;evt.common_evt.params.user_mem_release.mem_block.len == mem_block.len))
{
LOG_INFO(&amp;quot;USER_MEM_RELEASE\r\n&amp;quot;);
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long write only writes 4 packets</title><link>https://devzone.nordicsemi.com/thread/46938?ContentTypeID=1</link><pubDate>Tue, 08 Mar 2016 13:44:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:770d6f07-13ce-4411-ade9-b85dcbf9f002</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;What is the receiving side? It could have a limited queue, and the GATTS_STATUS in the prepare write response event would contain an error code if that is the case. Likely &amp;quot;Prepare Queue Full&amp;quot;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>