<?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>Questions regarding BLE notifications sending in loop</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/115916/questions-regarding-ble-notifications-sending-in-loop</link><description>Dear Nordic support, 
 I&amp;#39;ve done some testing to send many data in BLE notifications, and I have a question regarding the BLE stack implementation. We are using NCS v2.6.1, with the soft device controller. I have this piece of code running in a thread</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 31 Oct 2024 10:13:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/115916/questions-regarding-ble-notifications-sending-in-loop" /><item><title>RE: Questions regarding BLE notifications sending in loop</title><link>https://devzone.nordicsemi.com/thread/508639?ContentTypeID=1</link><pubDate>Thu, 31 Oct 2024 10:13:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:20cab9b2-c07e-423d-ba25-d771bb626926</guid><dc:creator>fr_adv</dc:creator><description>&lt;p&gt;Hello M. Nuguru,&lt;br /&gt;&lt;br /&gt;Thanks for the explanations. Just&amp;nbsp;remains a questionable point about this statement :&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;quot;Instead, if there are no free buffers, the bt_gatt_notify_uuid call will just return an error, basically saying, &amp;ldquo;Hey, I&amp;rsquo;m out of space to send more data right now.&amp;rdquo; &amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I think this is contradiction to the next paragraph about the BLE stack and Zephyr. Moreover, I don&amp;#39;t see any error log with the snippet in my previous comment.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The delays are not an issue in my case, it&amp;#39;s perfectly clear to me that the data shall be actually sent on the radio link, and acknowledged by the BLE peer (link layer&amp;nbsp;+ L2CAP I guess) before filling up BLE stack buffers again and sending more notifications.&lt;br /&gt;&lt;br /&gt;Thanks again for your feedback&lt;br /&gt;Best regards&lt;/p&gt;
&lt;p&gt;Aur&amp;eacute;lien&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions regarding BLE notifications sending in loop</title><link>https://devzone.nordicsemi.com/thread/508633?ContentTypeID=1</link><pubDate>Thu, 31 Oct 2024 09:38:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1f9019b-14e9-4650-acc0-2de1b50d432a</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;When you call bt_gatt_notify_uuid in a loop, the BLE stack tries to send out each notification using a set of buffers it has for data transmission. Now, you’ve got only a few of these buffers (BT_L2CAP_TX_BUF_COUNT=3 and BT_BUF_ACL_TX_COUNT=3), and they fill up pretty quickly. But the thing is, the BLE stack doesn’t just freeze your thread when all the buffers are in use. Instead, if there are no free buffers, the bt_gatt_notify_uuid call will just return an error, basically saying, “Hey, I’m out of space to send more data right now.”&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;You’d think that running this in a high-priority thread would hog all the CPU or that it would trigger the watchdog, but that’s not the case. Here’s why:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The BLE stack works asynchronously. It sends out the data over the air, and once a buffer is freed up (when the notification is sent), it becomes available for the next notification. This means your loop isn’t blocking everything — it just waits until there’s space again.&lt;/li&gt;
&lt;li&gt;Zephyr, the real-time operating system you’re using, is pretty clever. Even though your thread has a higher priority, the system uses preemptive multitasking. If your thread can’t do much because it’s waiting for buffers to free up, the system lets lower-priority threads (like your main thread that keeps the watchdog happy) run in the meantime. So, your main thread can still do its job, like resetting the watchdog, and everything stays stable.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Sometimes you’ll notice delays between notifications, and that’s because the BLE stack needs time to send out the data and free up buffers. Your loop doesn’t explicitly wait or yield, but the BLE stack and Zephyr handle this behind the scenes, keeping things from locking up. It is not very straightforward to explain the exact delays as it depends on many things as timings of the application thread and isr context/priorities/pre and post processing. All of these influence the times.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>