<?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>Sending data to BLE Client using Notifications - nRF Connect SDK</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81942/sending-data-to-ble-client-using-notifications---nrf-connect-sdk</link><description>Hello all, 
 I am currently working in a project that uses the nRF5340 SoC, nRF Connect SDK and Zephyr. The system has multiple sensors to measure various quantities such as temperature, humidity and pressure. All measurements are perfomed periodically</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 23 Nov 2021 12:45:02 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81942/sending-data-to-ble-client-using-notifications---nrf-connect-sdk" /><item><title>RE: Sending data to BLE Client using Notifications - nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/340335?ContentTypeID=1</link><pubDate>Tue, 23 Nov 2021 12:45:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1aa21965-3b39-45c6-b445-9c6ccf036de4</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="jbf12"]How will my application be notified that the supervision timeout has occurrred? Is there any callback function to be configured in order to receive that information?[/quote]
&lt;p&gt;You will get a callback whenever the link is terminated (assuming you provided a callback function for disconnected in the struct you pass to bt_conn_cb_register()) for any reason, and in that callback there is a status code that informs you of the &lt;em&gt;reason&lt;/em&gt;. This Bluetooth standard code is from the Bluetooth specification, and supervision timeout is 8.&lt;/p&gt;
[quote user="jbf12"]I am a bit confused by the last sentence. What do you mean by &amp;quot;without the host knowing about it&amp;quot;?[/quote]
&lt;p&gt;I mean that you will not be informed about any retransmissions, just when the packet has been ACKed (so you don&amp;#39;t know if it was immediately or it it took several attempts).&lt;/p&gt;
[quote user="jbf12"]Ok. I will do that. Do I need to add some kind of delay between transmissions?[/quote]
&lt;p&gt;Not in this case. If you wait for the callback, you know you can send/queue another notification. If you like you could also just continue to try to send with a small delay between each time and ignore the error you get before the previous packet is sent. this would be less efficient, though.&lt;/p&gt;
[quote user="jbf12"]Is there any limitation on the number of notify packets that can be sent per notification interval?[/quote]
&lt;p&gt;Yes, but not a hard limit. That depends on the event length and length of the packets. If the event length is long enough, you can send multiple packet. There is no fixed maximum number of packets per connection event. (this means that for high throughput you typically want to set the event length so that the event length is as long as the connection interval).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending data to BLE Client using Notifications - nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/340301?ContentTypeID=1</link><pubDate>Tue, 23 Nov 2021 10:49:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bbaba7b1-a9c8-44a0-bf65-cd7e1fc3a040</guid><dc:creator>jbf12</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;thanks for your answers.&lt;/p&gt;
&lt;p&gt;I have a few follow-up questions:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Yes, the link layer (which is either the Zephyr link layer or the SoftDevice controller) keeps track of transmitted packets and if they are acknowledged or not. If not acknowledged the packets are retransmitted until successfully transferred and acknowledged. If retransmissions keep failing so that there are no packets exchanged during a supervision timeout (which is a basic connection parameter), the link will be closed due to supervision timeout. &lt;strong&gt;In that case the application will be notified that a supervision timeout has occurred&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;How will my application be notified that the supervision timeout has occurrred? Is there any callback function to be configured in order to receive that information? Or is it the exact situation as when I disconnect my BLE Client from the BLE Peripheral and Zephyr tells me that the client has disconnected?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The callback is called when the packet has been ACKed on the link layer. Any retransmissions etc happen in the link layer &lt;strong&gt;without the host knowing about it&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I am a bit confused by the last sentence. What do you mean by &amp;quot;without the host knowing about it&amp;quot;? &lt;br /&gt;Correct me if my understanding is wrong: &lt;em&gt;bt_gatt_complete_func_t&lt;/em&gt; is called when the packet has been ACKed on the link layer and my Application will directly be notified about it. The host layer is &amp;quot;skipped&amp;quot; and the information is directly sent to the application.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Yes, you can do that. It could make sense to wait for the callback before you send more in this case.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Ok. I will do that. Do I need to add some kind of delay between transmissions? Is there any limitation on the number of notify packets that can be sent per notification interval?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending data to BLE Client using Notifications - nRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/340092?ContentTypeID=1</link><pubDate>Mon, 22 Nov 2021 13:42:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f198fa58-f335-4bbc-a9f3-588159709fee</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]The first doubt is whether notifications or indications should be used. I found this interesting &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/44482/use-cases-of-indications---when-is-it-better-to-use-indications-over-notifications"&gt;discussion&lt;/a&gt; and I understand that notifications are the better approach for my project, as there is indeed an ACK at the link layer and a minimal power consumption is also a desired goal. Do you see any reason to use indications?[/quote]
&lt;p&gt;The only reason to use indications is if you need confirmation in the application layer that the indication has been received. This is only useful in some very specific cases.&lt;/p&gt;
[quote user=""]In the aforementioned discussion, the first answer states that Notifications &amp;quot;are&lt;em&gt; still guaranteed to reach the target because of the link layer ACK&amp;quot;. &lt;/em&gt;I am interested to know what happens with the Acknowledge of the link layer. Is Zephyr checking that it is received? How does my implementation know that the ACK has been received?[/quote]
&lt;p&gt;Yes, the link layer (which is either the Zephyr link layer or the SoftDevice controller) keeps track of transmitted packets and if they are acknowledged or not. If not acknowledged the packets are retransmitted until successfully transferred and acknowledged. If retransmissions keep failing so that there are no packets exchanged during a supervision timeout (which is a basic connection parameter), the link will be closed due to supervision timeout. In that case the application will be notified that a supervision timeout has occurred.&lt;/p&gt;
[quote user=""]At the moment, I have implemented a custom service using the Nordic Uart Service (NUS) as reference and I can send data to the BLE Client by calling the function &lt;em&gt;bt_gatt_notify_cb. &lt;/em&gt;I am interested in the error situations. First, I tried to send data without any BLE Client being connected to the BLE Server. Secondly, I tried to send data without the BLE Client being subscribed. In both situations the function returns a negative value, which indicates that the function failed and the data could not be sent. So far so good, but shouldn`t the function retry to send the data until the ACK is received/timeout occurs?[/quote]
&lt;p&gt;No. You cannot send notifications (or indications) without a connection, and even if connected, the client needs to have enabled notifications/indications. It is correct and appropriate that the bt_gatt_notify_cb() function returns an error in this case.&lt;/p&gt;
[quote user=""]The function &lt;em&gt;bt_gatt_notify_cb&lt;/em&gt; takes two input parameters. The second paremeter is the struct &lt;em&gt;bt_gatt_notify_params&lt;/em&gt;, which contains the notification value callback &lt;em&gt;bt_gatt_complete_func_t&lt;/em&gt;. The Zephyr &lt;a href="https://docs.zephyrproject.org/latest/reference/bluetooth/gatt.html?highlight=bt_gatt_notify_params#c.bt_gatt_complete_func_t"&gt;documentation &lt;/a&gt;states that this is the &amp;quot;notification complete result callback&amp;quot;. Am I right to assume that this callback will be called when the BLE Server has received the ACK of the link layer sent by the BLE Client?[/quote]
&lt;p&gt;The callback is called when the packet has been ACKed on the link layer. Any retransmissions etc happen in the link layer without the host knowing about it.&lt;/p&gt;
[quote user=""]Each data set contains ~50Bytes and will be sent individually. I already modified the MTU in order to be able to send more than the 23 Bytes that are active per default. What would be the best way to send a significant amount of data sets (e.g. 100)? I was thinking of a for loop that calls the &lt;em&gt;bt_gatt_notify_cb&lt;/em&gt; function as many times as data sets are to be sent.[/quote]
&lt;p&gt;Yes, you can do that. It could make sense to wait for the callback before you send more in this case.&lt;/p&gt;
[quote user=""]When sending multiple consecutive data sets as notifications, is there any way to detect if one or more packages were not sent successfully?[/quote]
&lt;p&gt;As long as you did not get any supervision timeout, all packets were sent successfully.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>