<?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>Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/100276/dropped-packets-with-bt_nus_send</link><description>Greetings, 
 I am using the peripheral_uart Bluetooth nrf sample as a base for my custom application. 
 I have a ble_write_thread that just receives data on a message queue and calls the bt_nus_send function the same as the sample. And I also have a thread</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 13 Jun 2023 15:32:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/100276/dropped-packets-with-bt_nus_send" /><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/430817?ContentTypeID=1</link><pubDate>Tue, 13 Jun 2023 15:32:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5289c4eb-a99c-4afb-964f-b216836b4848</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Agreed; though in our case the number of disconnects exactly tracked the number of lost packets. The implication is that a packet could be queued while a disconnect was in progress and subsequently discarded perhaps when the connection was re-established. I forget now quite where I found that the stack knowingly discards queued data on a disconnect/connect, but there was something in the documentation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/430604?ContentTypeID=1</link><pubDate>Tue, 13 Jun 2023 04:47:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2636d91-34ac-49e5-8c1f-c8a4eef8d79f</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Yes, you are right, it can end in an endless loop. I will edit the code snippet&amp;nbsp; to exit after 10 attempts.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/430603?ContentTypeID=1</link><pubDate>Tue, 13 Jun 2023 04:44:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67dbcbb7-cd41-4def-8e6e-d572a40ae1f3</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;How would be correlate&amp;nbsp;mBleConnectionCounter to the number of lost packets? Maybe we can use this counter to tell the application of any possible data loss. Also, We cannot assume that every disconnect in such a scenario would definitely translate to data loss.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/430559?ContentTypeID=1</link><pubDate>Mon, 12 Jun 2023 16:03:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b812e59-8f3d-4a2b-a824-82c7e6905a55</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Perhaps the user&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/clockis"&gt;clockis&lt;/a&gt; could track the disconnect/connects; we found this helpful as it exactly corresponded to the number of missing packets. Something like this though this example is of course for the SDK not Zephyr&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            ...
            // Indicate number of connections for checking against missing packets
            mBleConnectionCounter++;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/430381?ContentTypeID=1</link><pubDate>Mon, 12 Jun 2023 08:11:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37929e90-6569-462a-a656-a3eaaf8ea586</guid><dc:creator>clockis</dc:creator><description>&lt;p&gt;Yes, it was indeed the handling of the Message Queue, thank you very much for your support and feedback!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/430374?ContentTypeID=1</link><pubDate>Mon, 12 Jun 2023 08:02:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13a29b42-94d7-40df-9e27-33e463dbfc2c</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I think handling your message queue incorrectly was the issue here based on the code snippet you provided. I am glad that it is solved now. Please mark my reply as verified so that others from this forum who have similar issue can be benefited..&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/430373?ContentTypeID=1</link><pubDate>Mon, 12 Jun 2023 08:00:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ba38e54-da1f-465d-b96b-b4f188590b45</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hugh, yes, that is one possible scenario where the uart data can be lost when you have a disconnect/connect sequence happening at the end of BLE range, but I did not think that this was the case as the description made me think that the data loss happens even without disconnect. Not sure how to handle such scenario when the softdevice just discards the packets. Seems like there is no error handling we can do here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/430293?ContentTypeID=1</link><pubDate>Fri, 09 Jun 2023 16:56:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:30445c6b-bb2a-48d8-9428-97891f320afc</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;I didn&amp;#39;t read this whole thread but something which might assist your basic lost packet issue: When a BLE disconnect/reconnect event occurs the data successfully sent to the Softdevice by the uart service handler but not yet physically transmitted in full via BLE using the uart code is simply discarded by the Nordic Softdevice without notification to the uart code. In our case this produces a single lost packet (we transmit in packets) for each disconnect followed by a connect, This happens more often near the edge of the BLE range.&lt;/p&gt;
&lt;p&gt;The only workaround we know is to query Central for any missing packets (or Central simply informs Peripheral of any missing packets using an embedded packet sequence number) and re-transmit those missing packets. This is a pain; if you find a simpler solution we would be happy to hear of it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/430290?ContentTypeID=1</link><pubDate>Fri, 09 Jun 2023 15:57:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:77e65334-02b2-4696-b56b-94cff83d0a4b</guid><dc:creator>clockis</dc:creator><description>&lt;p&gt;Actually, after a few modifications I have implemented this in my application and it seems to eliminate any further dropped packets.&lt;/p&gt;
&lt;p&gt;Thnk you very much for the support if you have any other comments for improvements or any other thoughts you have on this it would be greatly appreciated, otherwise I will be closing this ticket on Monday that I will have finalized my implementation&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/430283?ContentTypeID=1</link><pubDate>Fri, 09 Jun 2023 14:41:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:62fd2241-e5ba-4419-9017-55c3495b9cab</guid><dc:creator>clockis</dc:creator><description>&lt;p&gt;Because the Zephyr documentation suggests this implementation and also I do not want to make the producer threads wait.&lt;br /&gt;I will try this though.&lt;/p&gt;
&lt;p&gt;Wouldnt this result in an endless loop if the device disconnects while the producer thread is stuck in this loop? Something like this would also cause the watchdog of the producer thread to trigger.&lt;/p&gt;
&lt;p&gt;I just tried it and it makes the device unresponsive when it is on the edge of the Bluetooth range and it just freezes and stops transmitting, and after disconnecting the ble_write_thread and producer thread report 60 - 120 seconds of execution ( I am profiling the execution of the bt_nus_send and the producer thread )&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/430278?ContentTypeID=1</link><pubDate>Fri, 09 Jun 2023 14:11:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2cae2e01-a914-413e-b2a1-bb1ab5148b4f</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;purging a message queue might cause data loss in your case, when the message queue buffer is not empty. Why do you want to purge the message queue? I would suggest something like below&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void ble_transmit_data( ble_data_t ble_data )
{
    uint8_t retry_count = 0;
    
	while ((k_msgq_put(&amp;amp;ble_msgq, &amp;amp;ble_data, K_NO_WAIT) != 0) &amp;amp;&amp;amp; (retry_count++ &amp;lt; 10)) {
		/* Sleep for sometime. How long, is application specific */
		k_msleep(10);
	}
	
	if(retry_count == 10) { LOG_WRN(&amp;quot;Failed to add data to message queue&amp;quot;); }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/430261?ContentTypeID=1</link><pubDate>Fri, 09 Jun 2023 13:37:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0929ff1a-bec0-4c21-9b51-8aa41d249b4e</guid><dc:creator>clockis</dc:creator><description>&lt;p&gt;Hello Susheel,&lt;/p&gt;
&lt;p&gt;Thank you very much for the thorough and immediate response.&lt;/p&gt;
&lt;p&gt;Your previous message pointed me to look at the error handling when using&amp;nbsp;k_msgq_put to queue my data to the Message Queue by adding the code below:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;while (k_msgq_put(&amp;amp;ble_msgq, &amp;amp;ble_data, K_NO_WAIT) != 0) {
	/* message queue is full: purge old data &amp;amp; try again */
	k_msgq_purge(&amp;amp;ble_msgq);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Instead of just k_msgq_put on its own&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;k_msgq_put(&amp;amp;ble_msgq, &amp;amp;ble_data, K_NO_WAIT);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;After changing this, no packets were dropped even when I was close to the edge of the BLE range and had poor signal strength (although about 4% of messages were still getting dropped but that seems like a separate issue).&lt;/p&gt;
&lt;p&gt;The behavior was as your described and the BLE stack indeed cannot drop messages regardless of its connection settings (supervision timeout, ACL_BUF size, etc.). So it definitely was causing the issue I was seeing as messages were not being queued correctly in the message queue and did not arrive correctly in the ble_write_thread and thus were not fed to the bt_nus_send.&lt;br /&gt;&lt;br /&gt;Sorry for spamming with a double post I did it just before trying the modification mentioned above so it was premature.&lt;/p&gt;
&lt;p&gt;Now I am facing a different issue but since this might not be entirely relevant I will open a separate ticket for that.&lt;/p&gt;
&lt;p&gt;Meanwhile, I am attaching some code snippets of the producer/consumer threads I have implemented and how they are used in case you can reproduce or spot any issues with my implementation.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Producer thread:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;File: producer.c

void producer_thread (void)
{
    for (;;) {
    
        send_data();
        
        k_msleep(1000);
        
    }
}

uint8_t data[25][30]; //Data are already stored in a buffer

void send_data ( void )
{
    ble_data_t ble_data;
    
    for (i=0;i&amp;lt;25;i++)
    {
        //Load data to ble_data
        memcpy(ble_data.data , data[i], len[i]);
        ble_data.len = len[i];
        
        ble_transmit_data(ble_data);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Consumer thread:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;File: consumer.c

typedef struct ble_data_t {
    uint8_t data[30];
    uint16_t len;
} ble_data_t;

void ble_transmit_data( ble_data_t ble_data )
{
	while (k_msgq_put(&amp;amp;ble_msgq, &amp;amp;ble_data, K_NO_WAIT) != 0) {
		/* message queue is full: purge old data &amp;amp; try again */
		k_msgq_purge(&amp;amp;ble_msgq);
	}
}

void ble_write_thread (void) //The consumer thread
{
    ret_code_t err_code;
    
    for (;;) {
    
        /* Wait indefinitely for data to be sent over bluetooth */
		if (k_msgq_get( &amp;amp;ble_msgq, &amp;amp;buf , K_FOREVER))
		{
			LOG_ERR(&amp;quot;Failed to get data from ble_msgq&amp;quot;);
			continue;
		}
		
		err_code = bt_nus_send(NULL, buf.data, buf.len);
		if (err_code) {
			LOG_WRN(&amp;quot;Failed to send data over BLE connection&amp;quot;);
		}
    
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you again for your thorough feedback it is very helpful!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Stavros&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/430226?ContentTypeID=1</link><pubDate>Fri, 09 Jun 2023 12:11:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:43258294-2756-45ab-82e7-7376565d5370</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user="clockis"]&lt;strong&gt;Q 1.&lt;/strong&gt; Given this what is the best way for a producer thread to pass data to this consumer thread that runs bt_nus_send? Zephyr FIFO? Zephyr Message Queue? and how should they be written as code if you could provide a very simple generic sample code?[/quote]
&lt;p&gt;I think before we even dive deeper into checking which data passing mechanism is best suited here, we first need to confirm that this is infact a producer/consumer problem that we are seeing. There is absolutely nothing wrong using the message queues, but it can matter how you are using it and how you are handling any errors you get while passing messages (due to queue being full or timedout).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Since you are doing this in the ble_write_thread and not in the bluetooth callbacks, I do not think this is caused by the possible blocking nature of&amp;nbsp;&lt;span&gt;bt_gatt_notify_cb.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Can you help me reproduce this or give me enough code snippets both in the producer and consumer so that I can attempt to make something similar to your use case?&lt;/p&gt;
&lt;p&gt;What you are seeing could also happen due to application not handling errors with message queues or if there is any other race condition in the context where you get raw data and how you queue and send them in the notification.&amp;nbsp;&lt;/p&gt;
[quote user="clockis"]Also the description above regarding the internal buffers being ovewritten was explained to me by a Zephyr community member on the Zephyr discord in detail, so I am just quoting their words and their explanation for it[/quote]
&lt;p&gt;Could you please provide a link to this. I am surprised that I did not hear about this, but if you provide a link to this discussion and if it is still relevant to the SDK version you are using, then I will also keep focusing on the possible bug in the BLE stack handling. For now, my focus is mostly on application.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/430170?ContentTypeID=1</link><pubDate>Fri, 09 Jun 2023 09:46:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:75f663e3-bd3e-44b4-9207-3d8aba2d201c</guid><dc:creator>clockis</dc:creator><description>&lt;p&gt;Hello Susheel,&lt;/p&gt;
&lt;p&gt;Please excuse me for double posting but if it is possible for you I would like an answer to&amp;nbsp;a more general question first before you respond to my previous comment because my issue is more general as well.&lt;/p&gt;
&lt;p&gt;How should someone send data using bt_nus_send assuming having a producer thread that periodically generates data and I assume a consumer thread that waits for that data and calls the bt_nus_send (just like the ble_write_thread in the peripheral_uart sample)? I am assuming a consumer thread that waits on the data and feeds it to bt_nus_send is the most ideal case for an application with multiple threads that want to send data to Bluetooth (if not please suggest another way).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Q 1.&lt;/strong&gt; Given this what is the best way for a producer thread to pass data to this consumer thread that runs bt_nus_send? Zephyr FIFO? Zephyr Message Queue? and how should they be written as code if you could provide a very simple generic sample code?&lt;/p&gt;
&lt;p&gt;I am inquiring about this because I have tried using FIFOs &amp;amp; Message Queue and I still get dropped messages&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Q 2.&lt;/strong&gt; Also when the device reaches close to the edge of the range and transmission slows down and ultimately disconnects because it&amp;#39;s out of range, when I get back close and connect&amp;nbsp;it again, it still transmits at a very slow speed like it&amp;#39;s still far away, what could be causing this?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you very much for your patience and support and I look forward to hearing from you!&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Stavros&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/429972?ContentTypeID=1</link><pubDate>Thu, 08 Jun 2023 11:41:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63c52bd8-ce73-4575-89fc-fbd8b53c5736</guid><dc:creator>clockis</dc:creator><description>&lt;p&gt;Hello Susheel,&lt;/p&gt;
&lt;p&gt;I have already performed the tests from the side of the application by checking the queued data sent to the bt_nus_send function and they are complete as expected and we are not receiving any errors from bt_nus_send or other messages.&lt;/p&gt;
&lt;p&gt;Besides, this dropping of packets does not happen when the device is close to the mobile phone (BLE central using the nRF Connect app for Android as well as the nRD Connect app for Windows) it only happens when approaching the edge of the Bluetooth range.&lt;/p&gt;
&lt;p&gt;When the device is close to the BLE central the transmission is complete, and successful, and all data arrive as expected, so to me, this shows that they&amp;#39;re queued correctly as this mechanism is not related to the BLE range/signal strength, etc.&lt;/p&gt;
&lt;p&gt;I am using a Zephyr MSGQ to wait for data in the ble_write_thread and this works perfectly. Queueing the data to the ble_write_thread with the MSGQ is irrelevant to the BLE stack. I don&amp;#39;t see how this mechanism could be affected by the Bluetooth range or closeness of our device and the BLE central.&lt;br /&gt;&lt;br /&gt;I will however try to perform the BLE sniffing and I will inform you asap but right now I am very much constrained in time and I am not sure when I will have the chance to do this.&lt;/p&gt;
[quote userid="6207" url="~/f/nordic-q-a/100276/dropped-packets-with-bt_nus_send/429920"]&lt;blockquote class="quote"&gt;&lt;div class="quote-user"&gt;clockis said:&lt;/div&gt;&lt;div class="quote-content"&gt;But when it is on the edge of the BLE range and the connection is poor it keeps retrying to send the same message for a long time while we are still feeding/queueing new data to it(which it queues in its internal BLE stack buffers for transmission). Which at some point&amp;nbsp;overwrites older data that were queued (in the internal BLE stack buffers) but not sent thus resulting in dropped packets (packets that were fed to bt_nus_send successfully but never sent to the BLE central because they got overwritten by newer data).&lt;/div&gt;&lt;/blockquote&gt;&lt;div class="quote-footer"&gt;&lt;/div&gt;
&lt;p&gt;I do not think that this should be possible to happen that the BLE stack internal buffers are somehow overwritten. Atleast I have not heard of this happening.&amp;nbsp;&lt;/p&gt;[/quote]
&lt;p&gt;Also the description above regarding the internal buffers being ovewritten was explained to me by a Zephyr community member on the Zephyr discord in detail, so I am just quoting their words and their explanation for it. Also I have seen it mentioned in other DevZone tickets:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/91818/bt_nus_send-takes-time-to-execute"&gt;bt_nus_send takes time to execute&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/87702/execution-time-of-bt_nus_send"&gt;Execution time of bt_nus_send&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you very much for your support! If you require any more info please let me know ( I will be doing the sniffing tests but if you could provide some feedback based on this it would be very helpful and greatly appreciated )&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Stavros&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/429920?ContentTypeID=1</link><pubDate>Thu, 08 Jun 2023 08:59:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:876317e6-cf90-4928-86b9-cc66a2f9e3a8</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi Stavros,&lt;/p&gt;
&lt;p&gt;Karl requested me to take over. I am looking at the information that you gave as below&lt;/p&gt;
[quote user="clockis"]But when it is on the edge of the BLE range and the connection is poor it keeps retrying to send the same message for a long time while we are still feeding/queueing new data to it(which it queues in its internal BLE stack buffers for transmission). Which at some point&amp;nbsp;overwrites older data that were queued (in the internal BLE stack buffers) but not sent thus resulting in dropped packets (packets that were fed to bt_nus_send successfully but never sent to the BLE central because they got overwritten by newer data).[/quote]
&lt;p&gt;I do not think that this should be possible to happen that the BLE stack internal buffers are somehow overwritten. Atleast I have not heard of this happening.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am assuming that you have double checked that your application is actually queuing full data using&amp;nbsp;&lt;span&gt;bt_nus_send (maybe print all data queued?) and you have confirmed here that you do not receive any error while sending notification. You also confirmed that the peer sees dropped packets. So the only thing that is remaining is to see the air traffic data. Can you please see it in the sniffer, that the notification data sent to the peer has missing data (dropped packets or overwritten data within the BLE stack)? If you queued data correctly and if you are not able to see few data it in the BLE sniffer, then something is happening within the BLE stack and we can focus our debugging direction into debugging the BLE stack issue.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But I am thinking this could be a producer and consumer problem in the application itself. Before we could dive deeper into two different directions, please provide the data sent and BLE sniffer so that we can narrow the problem to either application specific or the BLE stack specific.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/429845?ContentTypeID=1</link><pubDate>Wed, 07 Jun 2023 19:00:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f42e8a0e-40e5-4db3-aa0f-c5a8c76c2c5f</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Stavros,&lt;br /&gt;&lt;br /&gt;Thank you for your patience with this.&lt;/p&gt;
[quote user="clockis"]Excuse me for the incomplete information.[/quote]
&lt;p&gt;No need to apologize, I will just ask if I have any questions.&lt;br /&gt;&lt;br /&gt;Thank you for the clarifications.&lt;/p&gt;
&lt;p&gt;I will get back to you tomorrow with an update.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/429713?ContentTypeID=1</link><pubDate>Wed, 07 Jun 2023 09:22:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b158542b-d981-4560-9610-1d859fdcfdfb</guid><dc:creator>clockis</dc:creator><description>&lt;p&gt;Hello Karl,&lt;/p&gt;
&lt;p&gt;Kind reminder if you have any updates on this as this is a very important issue for our application.&lt;/p&gt;
&lt;p&gt;Thank you very much&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Stavros&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/429055?ContentTypeID=1</link><pubDate>Fri, 02 Jun 2023 15:33:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c5551bab-9947-4345-a3cb-ec380e0c23c6</guid><dc:creator>clockis</dc:creator><description>&lt;p&gt;Hello Karl,&lt;/p&gt;
&lt;p&gt;If you require any additional information&amp;nbsp;or clarifications or if you have any updates on this please let me know.&lt;/p&gt;
&lt;p&gt;Also please note that I am using a ring buffer as I am using the Zephyr Message Queue(which is implemented as a ring buffer) to pass the generated data from the producer thread to the consumer(ble_write_thread).&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Stavros&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/428485?ContentTypeID=1</link><pubDate>Wed, 31 May 2023 13:20:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6780e798-010f-474a-ba3a-5c768ba2b70d</guid><dc:creator>clockis</dc:creator><description>&lt;p&gt;Hello Karl,&lt;/p&gt;
&lt;p&gt;Excuse me for the incomplete information.&lt;/p&gt;
&lt;p&gt;Up until the change that requires the transmission of additional data we are transferring 341 bytes/second of data separated in separate 24 messages of various lengths that are queued to the ble_write_thread ( like the one used in peripheral_uart sample) that uses a Zephyr Message Queue to feed the data to the bt_nus_send.&lt;br /&gt;&lt;br /&gt;As mentioned above the ble_write_thread just waits on the Zephyr Message Queue and feeds the incoming data to the bt_nus_send just like in the peripheral_uart sample.&lt;/p&gt;
&lt;p&gt;With the new requirement we want to ideally send 21 x 341 = 7161 bytes/second and the hard requirement is to have &lt;strong&gt;NO dropped messages at all.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As I have understood after speaking with multiple Zephyr community members when called the bt_nus_send queues the data fed to it for transmission in the internal BLE stack&amp;#39;s buffers and the BLE stack is responsible to try and send them until it succeeds or the supervision timeout expires.&lt;/p&gt;
&lt;p&gt;But when it is on the edge of the BLE range and the connection is poor it keeps retrying to send the same message for a long time while we are still feeding/queueing new data to it(which it queues in its internal BLE stack buffers for transmission). Which at some point&amp;nbsp;overwrites older data that were queued (in the internal BLE stack buffers) but not sent thus resulting in dropped packets (packets that were fed to bt_nus_send successfully but never sent to the BLE central because they got overwritten by newer data).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;bt_nus_send never returns an error message&lt;/strong&gt; during this behavior( so no error handling is possible ) it always returns successfully but is executing/blocking for tens of milliseconds when this dropping of the packets happens(I am observing the execution time of the bt_nus_send (in the ble_write_thread.&lt;/p&gt;
&lt;p&gt;I have tried using the maximum number of BLE stack&amp;#39;s buffers (&lt;span&gt;CONFIG_BT_BUF_ACL_TX_COUNT=255&lt;/span&gt;) and the minimum supervision timeout (100 ms) so that the BLE stack can queue/buffer more data as well as disconnect when the transmission duration is too long but I still get some dropped packets when the device is in the edge of its range.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Stavros&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dropped packets with bt_nus_send</title><link>https://devzone.nordicsemi.com/thread/428322?ContentTypeID=1</link><pubDate>Wed, 31 May 2023 07:06:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f76c5f0-0165-4c7f-ad16-c91843db2459</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Stavros,&lt;br /&gt;&lt;br /&gt;The best approach to handle this will depend on your applications requirements and constraints, could you elaborate on the requirements to your data transfer?&lt;br /&gt;How much data will you generate, and how quickly will you do so, that you will be sending to the phone?&lt;br /&gt;&lt;br /&gt;In any case, the best way to approach this is to implement a local error handling after the call to queue the data for sending over the NUS service, so that you can handle it in the case that the data fails to queue due to the buffer being full.&lt;br /&gt;To handle this you could for example implement a ring-buffer, which you feed into the NUS service.&lt;br /&gt;Alternatively, you could handle the data that fails to queue in another way - for instance, if it is not important for your application that every packet of data makes it across the link you could discard this data just as well. I mention both these approaches since I do not know enough about your application to know which one fits your use-case.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>