<?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 samples</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/3804/long-write-samples</link><description>Hi All, 
 Are there any updated examples for nrf51822 for writing long charecteristics.
My Application has to receive more than 20 bytes at a time and send over uart. 
 I am using experimental/ble_app_uart as starting point. I tried modifying the on_write</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 19 Sep 2014 09:54:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/3804/long-write-samples" /><item><title>RE: long write samples</title><link>https://devzone.nordicsemi.com/thread/13745?ContentTypeID=1</link><pubDate>Fri, 19 Sep 2014 09:54:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:87fae60e-2321-4f04-a5a6-21cf8e83cc38</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;Your understanding is correct, as long as you remember to skip &amp;quot;length&amp;quot; number of bytes to find the next chunk. I do not have the capacity to recreate your project, so maybe you could provide some sample data and the associated uart prints you got from it? Maybe in a private message if you do not want to show too much of your work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: long write samples</title><link>https://devzone.nordicsemi.com/thread/13744?ContentTypeID=1</link><pubDate>Thu, 18 Sep 2014 20:02:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9e03016-7a26-45c6-a981-74b3386a2dcc</guid><dc:creator>Aashish Patel</dc:creator><description>&lt;p&gt;Hello,
I have tried parsing the mem_block we are passing to SD. But getting confused on the parser implementation. I have tried different methods but I am not getting result.  Referring to the user mem layout given &lt;a href="https://devzone.nordicsemi.com/documentation/nrf51/6.0.0/s110/html/a01006.html"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But I am getting inconsistent results. If I read length of memblock it shows proper value for less than 20 bytes value but above 20 bytes it shows same value.&lt;/p&gt;
&lt;p&gt;This is my understanding of user mem layout. So SD writes total value provided to it in chunks to user_mem_block. In case of long write to same characteristic with same handle but with increasing offset changed. So parser we will have to read first chunk then move chunk bytes ahead ..and check handle value again read chunk and so on till we get BLE_GATT_HANDLE_INVALID. I implemented a parser like this but didn&amp;#39;t get proper result.&lt;/p&gt;
&lt;p&gt;Then I just printed the contents of mem_queue.I was getting proper values till 35-36 bytes but then again some random bytes then remaining bytes.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;case BLE_GATTS_EVT_WRITE:
       								
					simple_uart_putstring(&amp;quot;In Write Event\n\r&amp;quot;);

					if (p_ble_evt-&amp;gt;evt.gatts_evt.params.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW)
					{
						  simple_uart_putstring(&amp;quot;In Write Req Now Op\n\r&amp;quot;);	
						  int i;
							for (i = 0; i &amp;lt; MEM_BLOCK_SIZE ; i++)
							{
								simple_uart_put(m_mem_block.p_mem[i]);
							}
							
					}
					simple_uart_put(&amp;#39;\n&amp;#39;);
					simple_uart_put(&amp;#39;\r&amp;#39;);
        break;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you can give me  a simple illustration of a parser then it would be great.
Forgot to mention I am using dongle running MCP firmware to send long write values over BLE.&lt;/p&gt;
&lt;p&gt;Please ignore if there are any typos (I haven&amp;#39;t had much sleep in last 2 days).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: long write samples</title><link>https://devzone.nordicsemi.com/thread/13743?ContentTypeID=1</link><pubDate>Tue, 16 Sep 2014 14:23:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b447ab8-0257-4c0e-a8dc-50988897fbea</guid><dc:creator>Aashish Patel</dc:creator><description>&lt;p&gt;Thanks your detailed response.
I will test with both approach where stack handles request and where application handles request.
In case of stack handling the memory, I would have to pass address and length of memory block to my data handler from on_write function in applicatio right ? ..
will try this things and update.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: long write samples</title><link>https://devzone.nordicsemi.com/thread/13742?ContentTypeID=1</link><pubDate>Tue, 16 Sep 2014 14:03:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:090ce05a-4b24-48f3-8643-a42b0cd76a7b</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;If you choose to let the stack handle the memory for you, you will not be able to see the individual chunks coming in until the execute happens. Then all of them will arrive in a single write event. If you let your application handle each request, they will arrive as BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST which you have to authorize one by one. You can choose between these behaviors by giving a mem block in mem_reply (stack handled) or NULL (app handled). The MSCs for the APP handled variant can be found here: &lt;a href="https://devzone.nordicsemi.com/documentation/nrf51/6.0.0/s110/html/a00856.html"&gt;devzone.nordicsemi.com/.../a00856.html&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: long write samples</title><link>https://devzone.nordicsemi.com/thread/13741?ContentTypeID=1</link><pubDate>Mon, 15 Sep 2014 15:21:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cfc041d2-6305-44fc-8315-88a6d3f3dbd6</guid><dc:creator>Aashish Patel</dc:creator><description>&lt;p&gt;as per your suggestion I have set reliable_wr flag for android to detect and following the sequence you have suggested. But I have one doubt on nordic app side.
I think I will have to modify on_write():
if (
(p_evt_write-&amp;gt;handle == p_nus-&amp;gt;rx_handles.cccd_handle)
&amp;amp;&amp;amp;
(p_evt_write-&amp;gt;len == 2)
)
{
if (ble_srv_is_notification_enabled(p_evt_write-&amp;gt;data))
{
p_nus-&amp;gt;is_notification_enabled = true;
}
else
{
p_nus-&amp;gt;is_notification_enabled = false;
}
}
else if (
(p_evt_write-&amp;gt;handle == p_nus-&amp;gt;tx_handles.value_handle)
&amp;amp;&amp;amp;
(p_nus-&amp;gt;data_handler != NULL)
)
{
p_nus-&amp;gt;data_handler(p_nus, p_evt_write-&amp;gt;data, p_evt_write-&amp;gt;len);
}
else
{
// Do Nothing. This event is not relevant to this service.
}&lt;/p&gt;
&lt;p&gt;and data_handler function
void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
{
for (int i = 0; i &amp;lt; length; i++)
{
simple_uart_put(p_data[i]);
}
simple_uart_put(&amp;#39;\n&amp;#39;);
}&lt;/p&gt;
&lt;p&gt;As per my understanding whatever mem_block we pass is populated in reliable write.
So in on write function Can I just send contents of mem_block byte by byte to console using simple_uart_put ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: long write samples</title><link>https://devzone.nordicsemi.com/thread/13740?ContentTypeID=1</link><pubDate>Mon, 15 Sep 2014 12:54:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea61f71d-3314-46b7-81d9-9f503f0cd81f</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;I am not exactly sure on how to do this from the Android side, sorry. Your app should call beginReliableWrite(), proceed with multiple writeCharacteristic() calls with chunks of 20-byte, then end with an executeReliableWrite(). This should trigger a USER_MEM_REQUEST, and after some delay, a GATTS_EVT_WRITE followed by a USER_MEM_RELEASE event. You might have to set the &amp;quot;reliable_wr&amp;quot; flag in the char_ext_props field to 1 when adding the characteristic for Android to discover this functionality.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: long write samples</title><link>https://devzone.nordicsemi.com/thread/13739?ContentTypeID=1</link><pubDate>Mon, 15 Sep 2014 12:41:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c26290c6-78ef-4688-ba55-1dde09e45536</guid><dc:creator>Aashish Patel</dc:creator><description>&lt;p&gt;I have increased MAX_TX_CHAR_LEN ..also added BLE_EVT_USER_MEM_REQUEST an passed pointer to mem buffer of size 100 ...changed ble_uart_code ..but still I see only 20 bytes on uart console output.&lt;/p&gt;
&lt;p&gt;Do I need to send data from peer (android app in chunks of 20 bytes ) .. for this to work properly...I have created a android for sending data.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: long write samples</title><link>https://devzone.nordicsemi.com/thread/13738?ContentTypeID=1</link><pubDate>Mon, 15 Sep 2014 08:12:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3cdd74c5-9b9f-4f25-97e5-249cd811d7b0</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;You will have to set BLE_NUS_MAX_TX_CHAR_LEN to something larger than 20.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: long write samples</title><link>https://devzone.nordicsemi.com/thread/13737?ContentTypeID=1</link><pubDate>Mon, 15 Sep 2014 07:36:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8656fb76-49ad-49a4-8d31-68f48e6f8f44</guid><dc:creator>Aashish Patel</dc:creator><description>&lt;p&gt;Thanks for quick response&lt;/p&gt;
&lt;p&gt;Reliable write would work for us as we want to write data (which is more than 20 bytes long) to a characteristic using android app. For eg: &amp;quot;Nordic semiconductor application&amp;quot;. This characteristic value should than be displayed on console.&lt;/p&gt;
&lt;p&gt;ble_app_uart is working fine for me. But it only displays 20 bytes no matter how much data we send.&lt;/p&gt;
&lt;p&gt;So what modifications should I make to this example and where to make it working for more than 20 bytes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: long write samples</title><link>https://devzone.nordicsemi.com/thread/13736?ContentTypeID=1</link><pubDate>Mon, 15 Sep 2014 07:27:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29a608e6-d96e-400d-b9f5-69f64dc5f0a4</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;I think you might be confusing long writes and long MTU.&lt;/p&gt;
&lt;p&gt;Long writes, also called &amp;quot;Reliable writes&amp;quot; or &amp;quot;Queued Writes&amp;quot;, allows you to reliably and simultaneously write multiple &amp;lt;=20-byte chunks to a single or multiple characteristic(s)/descriptor(s). It does not allow you to transfer more data per connection event than other functions. (There are some restrictions in peer memory, and you are not allowed to have overlapping regions.) See &lt;a href="https://devzone.nordicsemi.com/documentation/nrf51/6.0.0/s110/html/a00854.html"&gt;here for some MSCs&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you want to send more than 20 bytes, you will have to break it down into chunks. If you need to write all the chunks at the same time (i.e. you want to update some data display that continuously reads more than 20 bytes of data each update) you can use reliable writes. If you want to enable/disable multiple CCCDs you can use reliable writes. However, if you need to send more than 20 bytes per packet, that is not currently possible with the Nordic SoftDevices.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>