<?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 notification takes too long</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/95690/ble-notification-takes-too-long</link><description>Hello everyone, 
 
 I&amp;#39;m developing an application for an nrf52840 with the nrf connect VS Code extension. 
 The application runs three threads. One to acquire 40 bytes of data from a sensor at a frequency of 400Hz, another to process those data, and a</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 19 Jan 2023 08:09:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/95690/ble-notification-takes-too-long" /><item><title>RE: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/405598?ContentTypeID=1</link><pubDate>Thu, 19 Jan 2023 08:09:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b5bb3f7-1f17-4461-a43c-25258fc6c51c</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="Natan ALLARD"]I finally managed to fix my problem by changing the way I put the data in the FIFO, instead of using k_malloc I used k_fifo_alloc_put and it seems to be fixed.[/quote]
&lt;p&gt;Great, I am happy to hear that you were able to resolve the issue! :)&amp;nbsp;&lt;/p&gt;
[quote user="Natan ALLARD"]Thank you for your help and all the information you gave me.[/quote][quote user="Natan ALLARD"]In any case everything you told me was very helpful to optimize the application.[/quote]
&lt;p&gt;It is no problem at all, I am glad that you found the information helpful! :)&lt;br /&gt;&lt;br /&gt;Please do not hesitate to open up another ticket if you should encounter any other issues or questions in the future.&lt;br /&gt;&lt;br /&gt;Good luck with your development!&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: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/405526?ContentTypeID=1</link><pubDate>Wed, 18 Jan 2023 15:34:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c5b3baf9-ceed-4a18-9476-c0805559ba48</guid><dc:creator>Natan ALLARD</dc:creator><description>&lt;p&gt;Thank you for your help and all the information you gave me.&lt;/p&gt;
&lt;p&gt;I finally managed to fix my problem by changing the way I put the data in the FIFO, instead of using k_malloc I used k_fifo_alloc_put and it seems to be fixed.&lt;/p&gt;
&lt;p&gt;In any case everything you told me was very helpful to optimize the application.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/405483?ContentTypeID=1</link><pubDate>Wed, 18 Jan 2023 13:10:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9c352b7-b1d0-4927-9bc2-d98c76411386</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="Natan ALLARD"]Yes sorry If I wasn&amp;#39;t clear. The I can see logs prior to the crash. When i activate the notification it sends some of the data (I know because I see it on the nrf mobile app and because I print logs) then it crashes.[/quote]
&lt;p&gt;No need to apologize, I will just ask if anything is unclear :)&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Great to know that you are able to see logs up until the crash. Have you added any local error handling to the notify function call?&lt;br /&gt;For starters, you could add some logging to alert you in the case that the notify function call fails.&lt;/p&gt;
[quote user="Natan ALLARD"]I understand the ring buffer but isn&amp;#39;t it similar to the FIFO I implemented ?[/quote]
&lt;p&gt;Yes, the difference between the ring buffer and the FIFO is that the ring buffer will start to overwrite itself instead of overflowing, in the case that data is starting to back up significantly. This way, you could avoid crashing due to the buffer overflowing, for instance.&lt;/p&gt;
[quote user="Natan ALLARD"]I need to send them in a consecutive order.[/quote]
&lt;p&gt;Thank you for clarifying. Does the data ever &amp;#39;time out&amp;#39;? I.e is there ever a time threshold where &amp;#39;old&amp;#39; data no longer will be useful?&lt;br /&gt;If so, then that threshold could be used as a natural limitation on the FIFO buffer size.&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: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/405375?ContentTypeID=1</link><pubDate>Wed, 18 Jan 2023 07:21:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c5e1a45-59f6-4254-81a6-5b3477b03e05</guid><dc:creator>Natan ALLARD</dc:creator><description>&lt;p&gt;Yes sorry If I wasn&amp;#39;t clear. The I can see logs prior to the crash. When i activate the notification it sends some of the data (I know because I see it on the nrf mobile app and because I print logs) then it crashes.&lt;/p&gt;
&lt;p&gt;I need to send them in a consecutive order. I understand the ring buffer but isn&amp;#39;t it similar to the FIFO I implemented ?&lt;/p&gt;
&lt;p&gt;Thank you,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/405369?ContentTypeID=1</link><pubDate>Wed, 18 Jan 2023 07:12:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6057787b-0079-4c35-8c94-9078bc1609f9</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="Natan ALLARD"]I am not seeing any log at all when it crashes.[/quote]
&lt;p&gt;Yes, but are you seeing logs prior to the crash? Are you seeing any logs at all?&lt;/p&gt;
[quote user="Natan ALLARD"]And I think I understand but what can I do to fix this?[/quote]
&lt;p&gt;The best approach to this depends on how important it is whether every sensor measurement makes it across to the peer or not - will the sensor data ever time-out, or stop being useful to the central, or should all data be sent in consecutive order and if it can not then the connection should be terminated?&lt;br /&gt;In case of the latter I would recommend implementing a ring buffer as mentioned in my previous comments.&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: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/405171?ContentTypeID=1</link><pubDate>Tue, 17 Jan 2023 09:08:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c03021e-3827-4328-a855-b982327bca2e</guid><dc:creator>Natan ALLARD</dc:creator><description>&lt;p&gt;Thank you for these information.&lt;/p&gt;
&lt;p&gt;I am not seeing any log at all when it crashes.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;And I think I understand but what can I do to fix this?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/405156?ContentTypeID=1</link><pubDate>Tue, 17 Jan 2023 07:44:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2aa2c3f-874b-4fc2-91e9-b09cc75f146e</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="Natan ALLARD"]I don&amp;#39;t manage to get any error code printed even though I have indeed activated the logging with[/quote]
&lt;p&gt;Is it just the error code that is missing from the logs, or are you not seeing any logs at all?&lt;/p&gt;
[quote user="Natan ALLARD"]So after sending there shouldn&amp;#39;t be data anymore on the peripheral.[/quote]
&lt;p&gt;Yes, but in the case of a transmission that is not acknowledged (such as if a packet is dropped) then the data is not deleted until the packet is acknowledged by the peer.&lt;br /&gt;So the device will keep trying to send the same packet until it either succeeds, or the connection times out.&lt;br /&gt;In the latter case it will keep trying to send the same packet until the Connection Supervision Timeout occurs, which in the mean time would have filled up the ring buffer with unsent sensor samples.&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: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/405019?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2023 12:21:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03955255-d3fa-4729-9fac-b4cbf2bb8e97</guid><dc:creator>Natan ALLARD</dc:creator><description>&lt;p&gt;I don&amp;#39;t manage to get any error code printed even though I have indeed activated the logging with&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_LOG=y
CONFIG_LOG_PRINTK=y
CONFIG_DEBUG_THREAD_INFO=y

CONFIG_BT=y
CONFIG_BT_DEBUG_LOG=y&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/405018?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2023 12:18:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fe9d2ba-7a3b-447f-b918-18a4ef527236</guid><dc:creator>Natan ALLARD</dc:creator><description>&lt;p&gt;Yes, from what I understood when the FIFO is read, the data is supposed to be removed from it. And after sending the data I use k_free to free the memory of the allocated before with k_malloc.&lt;/p&gt;
&lt;p&gt;So after sending there shouldn&amp;#39;t be data anymore on the peripheral.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/405014?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2023 12:07:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13980280-89fb-45bd-a611-ce2b84307f1a</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Yes - you can change this to match the requirements of your application.&lt;br /&gt;But, assuming 4 s Connection Supervision Timeout means that you could potentially have 40*400*4 = 64 kB of unsent data when the connection times out.&lt;br /&gt;In the worst case scenario (with a really poor connection) you could only be getting through a packet every ~4s, which could cause your ring buffer to overflow as well, but in this case the connection is basically lost for all communication purposes.&lt;br /&gt;&lt;br /&gt;Does the data ever &amp;#39;expire&amp;#39;? / does there ever come a point from which the data no longer is useable to the central?&lt;br /&gt;If so, you should change the supervision timeout to match this requirement, or have the ring buffer start to overwrite unuseful data as soon as this happens.&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: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/404996?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2023 10:54:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3cfe3291-1fa5-4a50-8c0d-3a9d695073df</guid><dc:creator>Natan ALLARD</dc:creator><description>&lt;p&gt;Ok i see, the connection supervision timeout is still at default value so 4s I guess.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/404993?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2023 10:50:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc58702a-badd-481e-a263-42e55531df69</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Do you have logging enabled for your project?&lt;br /&gt;If so, the error code should be printed before it resets due to the returned error.&lt;br /&gt;You could then implement local specific error handling for the function that returns the error.&lt;br /&gt;&lt;br /&gt;I would then also recommend considering to create a ring buffer that can be used to cache the sensor data that fails to be queued, so that you do not loose it.&lt;br /&gt;This buffer should be big enough to accommodate all the data that could build up before the connection supervision timeout occurs.&lt;br /&gt;Dropped packets are also the reason why you should make sure that your connection event length is longer than what is needed to send a single sensor measurement, since you might need to re-send built-up packets from previously lost packets in addition to the new samples.&lt;br /&gt;How long is the duration of the connection supervision timeout in your application?&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: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/404979?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2023 10:09:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:455c4798-fda3-4cc6-a9f4-9ef4ffac5993</guid><dc:creator>Natan ALLARD</dc:creator><description>&lt;p&gt;Ok thank you I understand better and after reading zephyr documentation it says that the default connection interval is 30ms so that matches.&lt;/p&gt;
&lt;p&gt;Regarding the buffer overflow, I don&amp;#39;t really see it because it crashes down and reboot when I try to send the data.&lt;/p&gt;
&lt;p&gt;I tried with a lower acquisition frequency and it goes without a problem. that&amp;#39;s what led me to think the buffer is overflowing because it gets filled faster than the sending function can empty it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/404976?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2023 10:01:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:428e33f8-3168-4e83-b5e3-f9c3ec408722</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="Natan ALLARD"]MAX_CONN_EVENT_LEN_DEFAULT[/quote]
&lt;p&gt;Connection event length is indeed the length available in a single connection event, but the time between each of these events are determined by the Connection Interval, which is part of the connection parameters, so it is the Connection Interval that has the biggest impact on the latency here.&lt;/p&gt;
[quote user="Natan ALLARD"]My device is a peripheral and I use the Nordic connect mobile app as a central. Therefore I don&amp;#39;t know the size of the app buffer.&amp;nbsp;[/quote]
&lt;p&gt;Thank you for clarifying.&lt;br /&gt;By this do you mean that you are seeing the buffer overflow on the central side?&lt;br /&gt;Or is the issue that the call to queue the data for sending on the peripheral side fails due to the buffer overflow? If so, what exactly does the log say when this happens?&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: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/404946?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2023 08:05:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4627ed8-0e9c-4a4f-93a6-982048b9c6a8</guid><dc:creator>Natan ALLARD</dc:creator><description>&lt;p&gt;Yes Karl is right, I am not sending the data with advertising.&lt;/p&gt;
&lt;p&gt;But thank you for your answer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/404945?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2023 08:02:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f0506f0-e7f1-4bb8-a870-9822d1c264d4</guid><dc:creator>Natan ALLARD</dc:creator><description>&lt;p&gt;Hello, thank you for your answer.&lt;/p&gt;
&lt;p&gt;I thought I configured the connection interval to be 7812us (which I believe is the time to let 9 packet be exchanged on each connection event) with CONFIG_BT_CTLR_SDC_MAX_CONN_EVENT_LEN_DEFAULT. Is it the right way to do it ?&lt;/p&gt;
&lt;p&gt;My device is a peripheral and I use the Nordic connect mobile app as a central. Therefore I don&amp;#39;t know the size of the app buffer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Natan&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/404942?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2023 07:51:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3805308d-e5e0-4fd6-b16d-2792d58bb118</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;You are correct that a random delay between 0 and 10 ms is added before every advertising to avoid consecutive collisions between advertising devices, but I do not get the impression that Natan intends to transfer the measurements using advertising packets since they mention that it is important that every measurement makes it across to the other device - which you can not guarantee with an advertisement (it is of course not&amp;nbsp;&lt;em&gt;guaranteed&amp;nbsp;&lt;/em&gt;with a BLE connection either, but at least you will be notified if the transmission fail so that it will be tried again).&lt;br /&gt;&lt;br /&gt;As you mention this advertising delay makes synchronization with an advertising device hard, since the exact time of the advertisements will drift a lot over time.&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: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/404941?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2023 07:47:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e387e9c-c348-4296-be16-6a6fc9178a45</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]&lt;span&gt;&lt;span&gt;If my calculations are good, it should take 868µs to send a packet. But when I measure the time taken by the&amp;nbsp;&lt;/span&gt;&lt;/span&gt;bt_gatt_notify it is around 20ms.&amp;nbsp;[/quote]
&lt;p&gt;To easily verify the on-air time it will take to send a packet you can &lt;a href="https://devzone.nordicsemi.com/power/w/opp/2/online-power-profiler-for-bluetooth-le"&gt;use the Online Power Profiler&lt;/a&gt;, for instance :)&amp;nbsp;&lt;br /&gt;The reason why you are seeing 20 ms here is likely that it is the Connection Interval used for the connection where the data is sent.&lt;br /&gt;The shortest possible Connection Interval for BLE communication is 7.5 ms, which would mean that you on average will send 120 bytes every connection event (7.5 ms).&lt;br /&gt;Your buffer will need to be able to store this, and potentially some additional packets of this size in case multiple packets of this size suddenly is sent in a single connection event due to a previous packet loss, for instance.&amp;nbsp;&lt;br /&gt;How large is your receiving buffer currently?&lt;br /&gt;Is this a central or peripheral device you are developing?&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: BLE notification takes too long</title><link>https://devzone.nordicsemi.com/thread/404875?ContentTypeID=1</link><pubDate>Fri, 13 Jan 2023 20:58:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:adbda0ae-ea2e-415b-a4a1-f84ea82fc774</guid><dc:creator>PjGlasso</dc:creator><description>&lt;p&gt;I recall an automatic 10ms delay is added &lt;a href="https://youtu.be/CJcLabp42b4?t=462"&gt;delay in BLE advertise&lt;/a&gt;&amp;nbsp;to advertising packet to avoid collisions. So I would look there?&lt;/p&gt;
&lt;p&gt;maybe just send the data or a sync with the advertising , or like a broadcast with a timestamp? 20ms seams like the minimum but someone else could chime in and clear that up. TIA ;-)&lt;/p&gt;
&lt;p&gt;HTH&lt;/p&gt;
&lt;p&gt;GL :-p&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>