<?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>Use NUS Service on bonded devices without discovery</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/59957/use-nus-service-on-bonded-devices-without-discovery</link><description>Hi, 
 I am developing a system with 2 nrf52840 devices, communicating via the NUS Service. I am programming both the central and peripheral project. I am using the NRF5 SDK with S140 Softdevice on both sides. 
 I am trying to speed up the connection procedure</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 23 Apr 2020 05:37:32 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/59957/use-nus-service-on-bonded-devices-without-discovery" /><item><title>RE: Use NUS Service on bonded devices without discovery</title><link>https://devzone.nordicsemi.com/thread/246143?ContentTypeID=1</link><pubDate>Thu, 23 Apr 2020 05:37:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6e9ac51-97fd-4a22-8e8b-17640a65e814</guid><dc:creator>BjoernSchmitz</dc:creator><description>&lt;p&gt;Ok, thanks. I will try that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use NUS Service on bonded devices without discovery</title><link>https://devzone.nordicsemi.com/thread/246069?ContentTypeID=1</link><pubDate>Wed, 22 Apr 2020 13:42:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64ce29c8-c456-41b6-9d6d-a376d2005045</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Thank you for your clarification Björn!&lt;/p&gt;
&lt;p&gt;The reason the MTU negotiation is initialized upon connection is that the ble_conn_params.c file starts this negotiation for you upon a connected event. In order to skip/avoid the MTU negotiation, you can remove the ble_conn_params.c file from your project. Keep in mind that there are some other functions in this file as well that you&amp;#39;ll miss out on.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use NUS Service on bonded devices without discovery</title><link>https://devzone.nordicsemi.com/thread/245878?ContentTypeID=1</link><pubDate>Tue, 21 Apr 2020 14:35:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:281f4a38-7239-43d2-8887-c0997c0ce4ad</guid><dc:creator>BjoernSchmitz</dc:creator><description>&lt;p&gt;Tanks, but I already know this Blog Post and it really helped me back then, when I searched for it. However,&amp;nbsp;throughput is not the Issue here. I measured Latency from peripheral to host as about one Connection Interval, which is set to 7,5 ms. This is as good as it can get, according to Bluetooth Spec.&lt;/p&gt;
&lt;p&gt;What I am trying, is to minimize the delay from start of advertising, till receiving the first application data package on the central. My problem is that when I set&amp;nbsp;&amp;nbsp;&lt;span&gt;NRF_SDH_BLE_GAP_EVENT_LENGTH&amp;nbsp; to something different from 23, my packets are blocked until the MTU size is negotiated between Host and peripheral (NRF_BLE_GATT_EVT_ATT_MTU_UPDATED&amp;nbsp;received).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I understand why this is happening,&amp;nbsp;what I would like to know is if it is possible to directly start a connection with a higher MTU size then 23, when the peripheral has been bonded before. Thus, I could skip negotiating the maximum MTU size between Peripheral and Central and could directly start sending application data.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Bj&amp;ouml;rn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use NUS Service on bonded devices without discovery</title><link>https://devzone.nordicsemi.com/thread/244984?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 12:21:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02bab21e-dfd2-4b49-92ab-52fee7c2c233</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;That&amp;nbsp;&lt;span&gt;NRF_SDH_BLE_GAP_EVENT_LENGTH should be sufficient. Did you take a look at the blog post I linked to in order to see how to best increase the throughput? I&amp;#39;m having some trouble seeing what exactly is causing this. Are you able to upload a sniffer trace for me to take a look?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Simon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use NUS Service on bonded devices without discovery</title><link>https://devzone.nordicsemi.com/thread/244837?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 05:34:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f91ad753-4f73-444f-8c77-b7181e06a67c</guid><dc:creator>BjoernSchmitz</dc:creator><description>&lt;p&gt;Yes, NRF_SDH_BLE_GATT_MAX_MTU_SIZE in file sdk_config.h is set to 247 for both devices, so I expect that these values are used by default. And this seems to be correct, since&amp;nbsp;I receive the&amp;nbsp;&lt;span&gt;NRF_BLE_GATT_EVT_ATT_MTU_UPDATED event without asking for&amp;nbsp;changing the MTU size from my application.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;NRF_SDH_BLE_GAP_EVENT_LENGTH&amp;nbsp; is set to 320 on both device. Is this correct, or would you suggest a higher value? I tried to enlarge this value but this did not have any effect.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use NUS Service on bonded devices without discovery</title><link>https://devzone.nordicsemi.com/thread/244653?ContentTypeID=1</link><pubDate>Wed, 15 Apr 2020 09:54:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a190368-e7a2-48ba-b9c5-02019976a9a7</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Yes, I did. Very sorry about that. I have updated my previous reply to include the link to the blog post I mentioned now.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is the MTU size set to 247 in both devices by default? You might have to increase the NRF_SDH_BLE_GAP_EVENT_LENGTH for the devices to have enough time to transfer packets with an MTU size of 247, what is this set to in your application?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use NUS Service on bonded devices without discovery</title><link>https://devzone.nordicsemi.com/thread/244478?ContentTypeID=1</link><pubDate>Tue, 14 Apr 2020 13:56:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96c32ef9-c468-46dc-bf57-15f6544a7f19</guid><dc:creator>BjoernSchmitz</dc:creator><description>&lt;p&gt;Hi, did you forget to add a link to your comment?&lt;/p&gt;
&lt;p&gt;I finally found the problem. I still don&amp;#39;t know exactly how to fix this, though. It seems that sending data is blocked by an ongoing&amp;nbsp;&lt;span&gt;ATT_MTU exchange.&lt;/span&gt; I attached the trace log from my peripheral device:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/logTrace.txt"&gt;devzone.nordicsemi.com/.../logTrace.txt&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;What&amp;nbsp;I do, is starting to send data as soon as I receive the&amp;nbsp;BLE_NUS_EVT_COMM_STARTED event from the&amp;nbsp;NUS&amp;nbsp;module. Data is sent in 20 ms Interval.&lt;/p&gt;
&lt;p&gt;I would expect to receive a&amp;nbsp;BLE_NUS_EVT_TX_RDY event right after sending that first data package. However, this event is received more than 100 ms after my first attempt to send data. I also logged the answer I receive from&amp;nbsp;ble_nus_data_send. The function always returns 8, which is&amp;nbsp;&amp;quot;&lt;span&gt;NRF_ERROR_INVALID_STATE&amp;quot;, for my firsts attempts.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It seems that shortly after receiving the GATT&amp;nbsp;event NRF_BLE_GATT_EVT_ATT_MTU_UPDATED,&amp;nbsp; ble_nus_data_send&amp;nbsp;returns 0 and data is transferred.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I looked deeper in the code of ble_nus_data_send and I can say for sure, that the following if statement never evaluates to true.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;    if (!p_client-&amp;gt;is_notification_enabled)
    {
        return NRF_ERROR_INVALID_STATE;
    }&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thus, &amp;quot;return NRF_ERROR_INVALID_STATE&amp;quot; is skipped from the first time, I call the function. Instead,&amp;nbsp;sd_ble_gatts_hvx, which is called at the end of&amp;nbsp;ble_nus_data_send, seems to return the error code 8. I looked to the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s132.api.v3.0.0%2Fgroup___b_l_e___g_a_t_t_s___f_u_n_c_t_i_o_n_s.html"&gt;API reference&lt;/a&gt;&amp;nbsp;of&amp;nbsp;sd_ble_gatts_hvx, which may return&amp;nbsp;NRF_ERROR_INVALID_STATE, if &amp;quot;An ATT_MTU exchange is ongoing&amp;quot;.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;To make sure that this really is the problem, I did set NRF_SDH_BLE_GATT_MAX_MTU_SIZE to the default value of 23 on peripheral and central side. Before it was&amp;nbsp;247. This did speed up the connection process massively. Now ble_nus_data_send&amp;nbsp;directly returns 0 after the characteristic has been notified, and I do not receive &amp;quot;NRF_BLE_GATT_EVT_ATT_MTU_UPDATED&amp;quot; anymore. I can now connect, encrypt and send data from peripheral to host&amp;nbsp;within about 70 to 80 ms. This would satisfy my needs in theory but skipping&amp;nbsp;the MTU update is not really an option,&amp;nbsp;since I want to maximize throughput, which is hard with an MTU size of 23. Is there a way&amp;nbsp;store the MTU size for bonded devices, so that both devices do not need to negotiate the MTU size on each connection?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Bj&amp;ouml;rn&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use NUS Service on bonded devices without discovery</title><link>https://devzone.nordicsemi.com/thread/244360?ContentTypeID=1</link><pubDate>Tue, 14 Apr 2020 08:58:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8aa5888f-3f3c-49c8-81be-c96806bba3c7</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;In order to maximize throughput for your application, I suggest you check out &lt;a href="https://www.novelbits.io/bluetooth-5-speed-maximum-throughput/"&gt;this blog post&lt;/a&gt;, which is very thorough on throughput. Please check out that to see if you have missed anything there. Next, I&amp;#39;m not able to say what is causing this delay with the information you&amp;#39;ve provided. Are you able to capture a sniffer trace so we can see what event causes this delay?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use NUS Service on bonded devices without discovery</title><link>https://devzone.nordicsemi.com/thread/244109?ContentTypeID=1</link><pubDate>Wed, 08 Apr 2020 14:34:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fcf8248-f845-4804-8c02-9a33502ad722</guid><dc:creator>BjoernSchmitz</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;thanks for the quick response. This helps a lot. My solution is to store handles, when bonding the devices, and reusing this handles for all later connections. And this actually does speed up the connection process, since I can skip discovery. It doesn&amp;#39;t help as much as I hoped it would, though.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Currently, I can establish a connection within less than 50 ms after advertising was started on peripheral side. Since I reuse the&amp;nbsp;handles, and both devices are bonded (thus pairing process should also be skipped), I would expect the device to directly be able to communicate via NUS. However, even though I start transmitting value notifications from the peripheral side, as soon as the connection is established, it takes another 100 ms (more or less) until the first notification reaches the central. It seems that the notifications are queued somewhere. Then 100 ms after the connection was established, I receive all notifications, which I did send&amp;nbsp;in the meantime.&lt;/p&gt;
&lt;p&gt;Do you have an idea&amp;nbsp;how to speed that up, or what could cause the initial delay? Min and max connection interval are already at 7.5 ms, so&amp;nbsp;that shouldn&amp;#39;t be the problem. After the initial delay, latency from peripheral to central side is constantly below 20 ms. So this problem seems to exist only directly after connecting.&lt;/p&gt;
&lt;p&gt;My aim is to transmit data from peripheral to central side, via NUS value notifications, within 100 ms (counted from start of advertising to the reception of the value notification in the NUS event handler on central side). Do you think that is possible? Currently, I managed to transfer data within 150 ms,&amp;nbsp;so I need a way to save at least another 50 ms, within the connection process.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Bjoern&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use NUS Service on bonded devices without discovery</title><link>https://devzone.nordicsemi.com/thread/244068?ContentTypeID=1</link><pubDate>Wed, 08 Apr 2020 11:37:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d9be3df1-4a73-4334-a8a4-49d15692581a</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Bjoern&lt;/p&gt;
&lt;p&gt;This has been discussed in length in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/8779/is-it-possible-to-bypass-service-discovery-in-s120-if-uuids-and-characteristics-of-peripheral-are-known"&gt;this thread&lt;/a&gt;, even though it is rather old it should still be relevant.&amp;nbsp; It should be fairly simple, seeing as if you know the handles you can just utilize these directly. It might be that some SDK functions are tied together and make some trouble, but I think you should be fine if you remove the discovery module from your project altogether.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>