<?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>Inconsistent BLE data rates</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/51935/inconsistent-ble-data-rates</link><description>Hello, 
 I&amp;#39;m working on a project where we are doing the following: 
 
 Collecting sensor data and storing it in an external SPI flash 
 Retrieving that sensor data from the SPI flash, reading it out into a module global array 
 Sending that sensor data</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 17 Sep 2019 14:08:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/51935/inconsistent-ble-data-rates" /><item><title>RE: Inconsistent BLE data rates</title><link>https://devzone.nordicsemi.com/thread/210168?ContentTypeID=1</link><pubDate>Tue, 17 Sep 2019 14:08:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97e54af1-e0d8-45a5-b871-1374c63db566</guid><dc:creator>matt-lionembedded</dc:creator><description>&lt;p&gt;In general I&amp;#39;ve found Dmitry&amp;#39;s final conclusion to be true. Packet streaming after a host-intiated communication is very quick, packet streaming after a client-initiated communication is slower. I was able to verify this on a variety of phones and apps. In fact, I found that during the &amp;quot;slow case&amp;quot; of streaming (i.e. client-initiated communication prior to packet streaming), if I sent any data at all from the host to the client the transfer speed would return to the higher rate for the remainder of the data being streamed for that page. Practically speaking, the solution here was to adjust our protocol such that:&lt;/p&gt;
&lt;p&gt;1. Client sends packet to Host indicating it is ready to send a new page&lt;/p&gt;
&lt;p&gt;2. (This is the important one) Host sends packet to Client ACK&amp;#39;ing the previous message (and functionally claiming priority on the Host&amp;#39;s radio stack for subsequent BLE activity)&lt;/p&gt;
&lt;p&gt;3. Client streams page of data to Host&lt;/p&gt;
&lt;p&gt;4. Repeat for every page&lt;/p&gt;
&lt;p&gt;All in all an interesting journey into interoperability between SoCs and commercial cellphones and bluetooth connection configuration.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Just to address the tx buffer/queue issue - This did not come in to play for me as in both fast/slow cases I was never adding more than one packet to the buffer at any given time. i.e., I am only adding a new packet once I&amp;#39;ve received the&amp;nbsp;&lt;span&gt;BLE_GATTS_EVT_HVN_TX_COMPLETE event, at which point the queue should be cleared.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inconsistent BLE data rates</title><link>https://devzone.nordicsemi.com/thread/210161?ContentTypeID=1</link><pubDate>Tue, 17 Sep 2019 13:54:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5a7e166-0154-4323-aaa4-c0af15efc8b7</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I think Dmitry is right, either the HandleValueNotification/Indication(HVX) tx buffers are not filled when ready, or the smartphone stacks lower the priority of BLE&amp;nbsp;tasks after inactivity.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I suggest you test a few different smartphones and see how they behave, you might be testing with a phone that has a poor BLE stack.&amp;nbsp;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;I also suggest you study how you queue your HVX tx buffers in your two cases. The ble_app_uart server example should serve as a template on how to properly queue your data.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inconsistent BLE data rates</title><link>https://devzone.nordicsemi.com/thread/209035?ContentTypeID=1</link><pubDate>Tue, 10 Sep 2019 20:32:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fa8b7a41-ef6e-4392-849a-078a008fe965</guid><dc:creator>Dmitry</dc:creator><description>[quote userid="83229" url="~/f/nordic-q-a/51935/inconsistent-ble-data-rates/209028"]&amp;nbsp;Is there something else I need to do to configure my device to use the additional tx_queue size, or is setting it in the above way sufficient?[/quote]
&lt;p&gt;As you figured out yourself - you need to fill whole tx queue to have any gain from these settings.&lt;/p&gt;
&lt;p&gt;It&amp;#39;s hard to say why the response time slows down (I&amp;#39;m not android programmer, maybe there are some settings in android API). AFAIK many phones have shared radio part for BT and wifi, and OS may increase BT priority for some time after host-initiated operation, after that shrinking BT timeslots to minimum - to give maximum resources for wifi... just my thoughts, you can try to disable wifi and see what&amp;#39;s happen.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inconsistent BLE data rates</title><link>https://devzone.nordicsemi.com/thread/209028?ContentTypeID=1</link><pubDate>Tue, 10 Sep 2019 18:47:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c34da562-cf30-4d06-af64-fc4e1c31a258</guid><dc:creator>matt-lionembedded</dc:creator><description>&lt;p&gt;Hi Dmitry,&lt;/p&gt;
&lt;p&gt;Thanks for the clarification. I was able to update the tx_queue size via the following code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;ble_cfg_t ble_cfg;
ble_cfg.conn_cfg.conn_cfg_tag = APP_BLE_CONN_CFG_TAG;
ble_cfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = 4;
err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &amp;amp;ble_cfg, ram_start);
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But this had no effect on the issue at hand (i.e. still seeing the fast/slow cases). I tested this with the extended event length and the default event length with the same results. I also tried a tx_queue_size of 8.&amp;nbsp;Is there something else I need to do to configure my device to use the additional tx_queue size, or is setting it in the above way sufficient?&lt;/p&gt;
&lt;p&gt;I see the same thing you&amp;#39;re seeing in the trace. For clarity, I was using nRFConnect app on Android for this test as the host. Is there a reason why it would respond so slowly (~75ms) in the &amp;quot;slow case&amp;quot; and more quickly (~5us) in the &amp;quot;fast case&amp;quot;? Is this something that is fixable on the device/firmware side, or are we at the mercy of the phones here? Is there a bluetooth configuration parameter that governs these response times?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;EDIT: Come to think of it, should the tx_queue_size even matter, since I&amp;#39;m not adding any new packets to the queue until I&amp;#39;ve already received&amp;nbsp;&lt;span&gt;BLE_GATTS_EVT_HVN_TX_COMPLETE?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inconsistent BLE data rates</title><link>https://devzone.nordicsemi.com/thread/209018?ContentTypeID=1</link><pubDate>Tue, 10 Sep 2019 16:45:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf26a662-f065-497f-a5d9-296202ef8c38</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi Matt,&lt;/p&gt;
&lt;p&gt;&lt;span&gt;BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT is hardcoded in stack, so this change will have no effect. Use&amp;nbsp;&lt;a class="el" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v6.1.1/group___b_l_e___c_o_m_m_o_n___f_u_n_c_t_i_o_n_s.html#ga4edae2bac8c68b672c0fa101ed2c687f"&gt;sd_ble_cfg_set&lt;/a&gt;&amp;nbsp;with &lt;em&gt;BLE_CONN_CFG_GATTS&lt;/em&gt;&amp;nbsp; to change it.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Increase of event length helps while your app is smart enough to provide next packet every time the previous one is acknowledged by the host (imagine, the path from TX_COMPLETE event to call of&amp;nbsp;sd_ble_gatts_hvx takes 50 usec - you will loose these 50 usec between every two-packet exchange).&amp;nbsp; Also, too long connection event will increase power consumption, because receiver is on for the whole connection event. Increasing of TX queue size gives you another boost - the stack always has buffers ready to send, the delay is minimal and not depends on your handler.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;From your trace I can assume that the source of your issue is the host - in slow case you can see long delays (up to 75 msec) between notification and ACK from host.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inconsistent BLE data rates</title><link>https://devzone.nordicsemi.com/thread/209012?ContentTypeID=1</link><pubDate>Tue, 10 Sep 2019 15:34:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca6e0c6b-fc10-43f7-95ae-2ac12c9a8c62</guid><dc:creator>matt-lionembedded</dc:creator><description>&lt;p&gt;Hi Dmitry,&lt;/p&gt;
&lt;p&gt;That diagram is accurate.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I attempted to increase the number of TX buffers in two ways:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Manually change the value in ble_gatts.h of&amp;nbsp;BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT to 4, 8, 12&lt;/li&gt;
&lt;li&gt;Increase&amp;nbsp;&lt;span&gt;NRF_SDH_BLE_GAP_EVENT_LENGTH to 80 (100ms in 1.25ms units) - this is the max expected conn interval despite sometimes being lower. I followed &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/28616/how-to-set-the-queue-size-of-notification"&gt;this ticket&lt;/a&gt;.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;span&gt;I did see an overall improvement using method 2 in the data throughput rates for both the fast transfer and the slow transfer scenarios, but still the same overall behavior (as shown in your diagram).&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Am I understanding correctly that the issue here seems to be related to number of packets sent per connection - i.e. in the fast case we are getting multiple packets per connection interval and in the slow case we are not?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I&amp;#39;ve attached a wireshark/sniffer log which demonstrates one page transfer in both the fast and slow transfer scenarios.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/datacapture_2D00_matt_2D00_20190910.pcapng"&gt;devzone.nordicsemi.com/.../datacapture_2D00_matt_2D00_20190910.pcapng&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inconsistent BLE data rates</title><link>https://devzone.nordicsemi.com/thread/208830?ContentTypeID=1</link><pubDate>Tue, 10 Sep 2019 08:23:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a3e5f18-37f4-4edc-9917-11224bcc8e6d</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Thank you for good clarification. Take a look on picture, did I undrstand right&amp;nbsp; what&amp;#39;s going on?&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1568102945535v2.png" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;As a generic suggestion that&amp;nbsp;helped me in&amp;nbsp;similar case, try to increase a number of TX buffers (&lt;a class="el" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v6.1.1/structble__gatts__conn__cfg__t.html#ae2a1156d8b06a6ccc70696f2372226cc"&gt;hvn_tx_queue_size&lt;/a&gt;) - the stack will always have something to send, even if your handler will be late to start of the next connection event.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inconsistent BLE data rates</title><link>https://devzone.nordicsemi.com/thread/208769?ContentTypeID=1</link><pubDate>Mon, 09 Sep 2019 20:04:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:012825c1-00c2-42cd-99e0-fc9e2bfa5e1d</guid><dc:creator>matt-lionembedded</dc:creator><description>&lt;p&gt;Hi Dmitry,&lt;/p&gt;
&lt;p&gt;Thank you for&amp;nbsp;your response.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll work on getting a sniffer trace, but here are some answers to your other questions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Softdevice/SDK:&lt;/strong&gt; SDK 15.3.0, s132 6.1.1&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;OS at client side:&lt;/strong&gt;&amp;nbsp;I&amp;#39;ve tested this using iOS and Android, but for the sake of our debugging lets say I&amp;#39;m using a Google Pixel 2 with Android OS 9, running nRFConnect&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Connection parameters:&amp;nbsp;&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Interval: 37.5ms&lt;/li&gt;
&lt;li&gt;Latency: 0&lt;/li&gt;
&lt;li&gt;Timeout: 5000ms&lt;/li&gt;
&lt;li&gt;MTU: 247, but i&amp;#39;ve limited the packet size to 23 bytes to make the device compatible with older phones that don&amp;#39;t support the larger MTU.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Page size:&lt;/strong&gt; up to 2048 bytes,&amp;nbsp;data being sent in each individual packet&amp;nbsp;is &amp;lt;= 23 bytes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;How fast is page read from SPI/&lt;/strong&gt;&lt;span&gt;&lt;strong&gt;are they preloaded into a buffer or reading starts just after receiving a command:&lt;/strong&gt; Measurements for the rates I&amp;#39;ve described in my original message were taken AFTER the read from SPI flash, so page read from SPI shouldn&amp;#39;t matter? In both cases, when the device knows it is time to send a new page of data, it retrieves the data from SPI flash and places it in a buffer. Once the buffer is loaded, I start measuring transfer rates, and unspool the buffer until all the bytes of the page are sent. If it is relevant, the actual read from SPI can happen either immediately after receiving a command (i.e. there is a new page available when the &amp;quot;ready for next page&amp;quot; command is received - this is the fast transfer rate case), or some hundreds of milliseconds after receiving a command (i.e. a new page was not ready when the &amp;quot;ready for next page&amp;quot; command is received, but became available sometime after - this is the slow transfer rate case).&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span&gt;In what way did you implement a flow control on device side when sending notifications?&lt;/span&gt;&lt;/strong&gt; Once the device is made aware that the app is ready to receive data, and the data has been retrieved from SPI flash into a buffer, I send the first packet from the buffer. Subsequent packets are triggered by the TX complete event (BLE_GATTS_EVT_HVN_TX_COMPLETE) being received by my *service*_on_ble_evt event handler - i.e. after the first packet is successfully sent, TX_COMPLETE is issued, I advance the pointer in my data buffer, send next packet, repeat. This is done so that I can ensure the previous notification was received before sending the next one (no packet loss).&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inconsistent BLE data rates</title><link>https://devzone.nordicsemi.com/thread/208768?ContentTypeID=1</link><pubDate>Mon, 09 Sep 2019 19:35:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08d0e4b1-f031-45b8-bf2e-24e82d37e845</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi Matt,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Could you provide more details - what softdevice are you using, what OS is at client side, what&amp;#39;s your connection parameters? what&amp;#39;s the size of a page? How fast is page read from SPI, are they preloaded into a buffer or reading starts just after receiving a command? In what way did you implement a flow control on device side when sending notifications? Also, a sniffer trace in both cases would be very helpful.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>