<?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>BLE data transfer problem</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/67488/ble-data-transfer-problem</link><description>Hello, 
 I&amp;#39;m using a development board PCA10040 with sdk 16.0 I&amp;#39;m trying to organize a data streaming between two devices. Nrf52 board collect data (27 bytes with interval of 500us) from sensor board via SPI and send it via NUS. 
 At other side I have</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 28 Oct 2020 16:32:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/67488/ble-data-transfer-problem" /><item><title>RE: BLE data transfer problem</title><link>https://devzone.nordicsemi.com/thread/277462?ContentTypeID=1</link><pubDate>Wed, 28 Oct 2020 16:32:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4569ba19-6616-4448-b642-fdd27fc454f7</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Sounds you have been able to get much better throughput now by larger notifications and more packets in each interval.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can call&amp;nbsp;sd_ble_gatts_hvx() until&amp;nbsp;NRF_ERROR_RESOURCES (error 0x13 = 19). Then you can wait for a BLE_GATTS_EVT_HVN_TX_COMPLETE event (0x57) and retry &lt;span&gt;sd_ble_gatts_hvx()&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Alternatively, instead of waiting for&amp;nbsp;&lt;span&gt;BLE_GATTS_EVT_HVN_TX_COMPLETE event&lt;/span&gt; you can just retry &lt;span&gt;sd_ble_gatts_hvx() from a timer also&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE data transfer problem</title><link>https://devzone.nordicsemi.com/thread/277425?ContentTypeID=1</link><pubDate>Wed, 28 Oct 2020 14:33:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b82cd795-5c7e-48e2-94ab-e70b92702e0d</guid><dc:creator>romulsre</dc:creator><description>&lt;p&gt;Thank you for response, &lt;br /&gt;&lt;br /&gt;As you suggested, I added (found in some example)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void gatt_evt_handler(nrf_ble_gatt_t * p_gatt, nrf_ble_gatt_evt_t const * p_evt)
{
    if((m_conn_handle == p_evt-&amp;gt;conn_handle) &amp;amp;&amp;amp;(p_evt-&amp;gt;evt_id == NRF_BLE_GATT_EVT_ATT_MTU_UPDATED))
    {
        m_ble_nus_max_data_len = p_evt-&amp;gt;params.att_mtu_effective - OPCODE_LENGTH - HANDLE_LENGTH;
        NRF_LOG_INFO(&amp;quot;gatt_event: ATT MTU is set to 0x%X(%d)&amp;quot;, data_length, data_length);
    }
    else if((m_conn_handle == p_evt-&amp;gt;conn_handle) &amp;amp;&amp;amp;(p_evt-&amp;gt;evt_id == NRF_BLE_GATT_EVT_DATA_LENGTH_UPDATED))
    {
        m_ble_nus_max_data_len = p_evt-&amp;gt;params.att_mtu_effective - OPCODE_LENGTH - HANDLE_LENGTH - 4;
        NRF_LOG_INFO(&amp;quot;gatt_event: Data len is set to 0x%X(%d)&amp;quot;, data_length, data_length);
    }
    NRF_LOG_DEBUG(&amp;quot;ATT MTU exchange completed. central 0x%x peripheral 0x%x&amp;quot;,
                  p_gatt-&amp;gt;att_mtu_desired_central,
                  p_gatt-&amp;gt;att_mtu_desired_periph);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I tryed to increase NRF_SDH_BLE_GAP_EVENT_LENGTH parameter but any value (diffent from the 6) give me &amp;quot;fatal error&amp;quot;.&amp;nbsp; &lt;br /&gt;When I changed linker configuration, changing softdevice RAM I was able to change this parameter.&lt;br /&gt;So, now I can receive 4 packets (243 bytes each one) and return ble event with code 0x57. After this I have error 0x13(19). Is it mean that I have softdevice buffer full?&lt;br /&gt;Could you please give me example how to implement for waiting on BLE_GATTS_EVT_HVN_TX_COMPLETE ? Provided by ble_app_att_mtu_throughput example is not fully clear...&lt;br /&gt;As I use 2 boards, should the configuration of both devices be the same ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE data transfer problem</title><link>https://devzone.nordicsemi.com/thread/276460?ContentTypeID=1</link><pubDate>Thu, 22 Oct 2020 13:23:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fed20453-9b82-46b4-80a2-73388e5ea62b</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;I recommend to check out the&amp;nbsp;ble_app_att_mtu_throughput example, which should negotiate and show the max throughput:&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/ble_sdk_app_att_mtu.html"&gt;https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/ble_sdk_app_att_mtu.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But here is a tip for you:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If possible try to reduce the number of notifications sent between the peers. For instance instead of sending many small data packets, try to send larger packets combining more data into a single notification packet. To allow this you should exchange max supported MTU and DLE size between the two peers by include nrf_ble_gatt_init() in your application:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void nrf_ble_gatt_evt_handler(nrf_ble_gatt_t * p_gatt, nrf_ble_gatt_evt_t const * p_evt)
{
	if(p_evt-&amp;gt;evt_id == NRF_BLE_GATT_EVT_DATA_LENGTH_UPDATED)
	{
		// p_evt-&amp;gt;params.data_length is the max length on-air
	}	
	if(p_evt-&amp;gt;evt_id == NRF_BLE_GATT_EVT_ATT_MTU_UPDATED)
	{
		// p_evt-&amp;gt;params.att_mtu_effective is the max MTU size		
	}	
	
	// Once both are updated, then you can for instance start sending notifications that are longer than 20bytes when calling sd_ble_gatts_hvx()/sd_ble_gatts_value_set().
}


/**@brief Function for initializing the GATT module.
 */
static void gatt_init(void)
{
    ret_code_t err_code = nrf_ble_gatt_init(&amp;amp;m_gatt, nrf_ble_gatt_evt_handler);
    APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;If you for instance set&amp;nbsp;NRF_SDH_BLE_GATT_MAX_MTU_SIZE and NRF_SDH_BLE_GAP_DATA_LENGTH to 247, and then wait for nrf_ble_gatt_evt_handler() you can find the most efficient data&amp;nbsp;length for your notification data to be &amp;#39;p_evt-&amp;gt;params.data_length-3&amp;#39;.&lt;/p&gt;
&lt;p&gt;Make sure that the characterstic can support this data length by setting add_char_params.max_len =&amp;nbsp;247 when init the characteristic.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After receiving the&amp;nbsp;&lt;span&gt;nrf_ble_gatt_evt_handler() you can now call&amp;nbsp;sd_ble_gatts_hvx() with larger data than 20bytes (which is default),&amp;nbsp;now you can allow packet of up to (p_evt-&amp;gt;params.data_length-3) bytes. This will allow you to send less packets, and should overall make it less likely that you experience&amp;nbsp;NRF_ERROR_RESOURCES and also increase throughput. (FYI: The &amp;#39;-3&amp;#39; is due to header in the packet).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Kenneth&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>