<?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>problem with subscription notification</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/96755/problem-with-subscription-notification</link><description>I have a central and peripheral implementation, with 2 nRF5340 devkits. On the peripheral side, I defined a GATT service with a line like this: 
 
 BT_GATT_CCC ( ccc_cfg_changed , 
 BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), 
 
 The ccc_cfg_changed function</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 02 Jan 2024 13:13:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/96755/problem-with-subscription-notification" /><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/462293?ContentTypeID=1</link><pubDate>Tue, 02 Jan 2024 13:13:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7e683539-9364-41aa-aead-8a446380049d</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Sorry, I have been on leave since August.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There are a few issues that you can track. Mainly this one:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/issues/56187"&gt;https://github.com/zephyrproject-rtos/zephyr/issues/56187&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But these may also be interesting:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/issues/31306"&gt;https://github.com/zephyrproject-rtos/zephyr/issues/31306&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/issues/46695"&gt;https://github.com/zephyrproject-rtos/zephyr/issues/46695&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/issues/44587"&gt;https://github.com/zephyrproject-rtos/zephyr/issues/44587&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/459608?ContentTypeID=1</link><pubDate>Sun, 10 Dec 2023 12:43:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5681f437-e7cf-4cd9-bbc7-909dad3d4408</guid><dc:creator>dtp</dc:creator><description>&lt;p&gt;Hi Edvin, I know this is an old ticket but this issue is still present on NCS v2.5.0 and I have had to implement work arounds as well.&lt;/p&gt;
&lt;p&gt;I was hoping there would be a way for the peripheral to reset any subscriptions on disconnections, but from what I understood that would mean not following the Bluetooth spec. I haven&amp;#39;t found a way to do this anyhow.&lt;/p&gt;
&lt;p&gt;I was wondering if there is a plan to address this issue. Also, is there a way to track it, maybe a Zephyr GitHub issue?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/418605?ContentTypeID=1</link><pubDate>Fri, 31 Mar 2023 13:04:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bdc23698-9e8b-489e-8b9e-c883b96c69ad</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Please note that we will be very short staffed next week due to public holidays here in Norway. I will be back in the office on April 11th. Sorry for the inconvenience.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/418604?ContentTypeID=1</link><pubDate>Fri, 31 Mar 2023 13:03:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ca3c313-6e02-4a1f-8b1d-442b7aeb015c</guid><dc:creator>Edvin</dc:creator><description>[quote user="frankbuss"]Will the fix then be mentioned in the release notes for a new SDK?[/quote]
&lt;p&gt;I would assume so. It is not finalized yet, but this ticket (with others) have triggered some actions, at least.&lt;/p&gt;
[quote user="frankbuss"]what is a safe delay which always work?[/quote]
&lt;p&gt;That is the issue. There is no delay which is guaranteed to work every time. It would depend on your connection interval, and the amount of packet loss. You can try to do some tests using your central application under different conditions (distance/surroundings) to see how long it takes. It may actually be that disabling and re-enabling notifications from the central will go faster in most cases than a &amp;quot;safe&amp;quot; delay, if the delay would allow for some packet loss.&lt;/p&gt;
&lt;p&gt;As I see it, this is the main issue. Adding a delay will work in most cases, but you are never 100% sure that the discovery has completed. In theory, you could only get one packet through every supervision timeout. Any slower than this, and the link will disconnect. In that case, it would take N*supervision timeout for the discovery complete, where N is the amount of packets needed to go back and forth before the service discovery is complete. This depends on the application, but you can probably do a sniffer trace and count the number of packets. However, if you want to be &amp;quot;that&amp;quot; safe, disabling and reenabling notifications are probably faster.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvi&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/417965?ContentTypeID=1</link><pubDate>Tue, 28 Mar 2023 18:19:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c5a9837-6904-465e-9bf7-5e396567096b</guid><dc:creator>frankbuss</dc:creator><description>&lt;p&gt;Ok, what is a safe delay which always work? Currently I&amp;#39;m using one second after connect. Will the fix then be mentioned in the release notes for a new SDK?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/417819?ContentTypeID=1</link><pubDate>Tue, 28 Mar 2023 07:48:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c51956f8-d9bb-4942-9a4f-6a77dc911dcd</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I have discussed this a bit with some of our developers. At this point, there is really no good workaround for this, other than adding a delay, as you have already done. Apparently, this is already being used in some of our use case applications (nRF Desktop, which is a wireless mouse/keyboard demo in NCS).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I see that there have been attempts to work around this, but none of them have been included so far in our released SDKs. Whether or not they will be included in the next one I don&amp;#39;t know.&lt;/p&gt;
&lt;p&gt;So for now, it seems you need to stick to the delay, unfortunately. Alternatively, on your central, you can try to enable, disable and re-enable notifications. It seems a bit unnecessary, and I have not tested it, but I think you will then see the &amp;quot;notifications enabled&amp;quot; callback immediately upon the connect, followed by a &amp;quot;notifications disabled&amp;quot; event, and then a &amp;quot;notifications enabled&amp;quot; event. You can use that last event to know for sure that the notifications have been enabled.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/416981?ContentTypeID=1</link><pubDate>Thu, 23 Mar 2023 08:44:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1abff0c1-b180-4b77-a6c1-13cef325a879</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I am sorry for the late reply. I just wanted to let you know that I have investigated a bit more, and I can confirm what you are seeing. I hoped the service discovery on the central was just a &amp;quot;dummy service discovery&amp;quot;, where it also used information stored in the bonding data, but that seems to not be the case.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have created an internal ticket, and I will let you know when I hear anything.&lt;/p&gt;
&lt;p&gt;BR,&lt;br /&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/413646?ContentTypeID=1</link><pubDate>Mon, 06 Mar 2023 21:49:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:435383f9-339c-483f-8485-f693687c6078</guid><dc:creator>frankbuss</dc:creator><description>&lt;p&gt;No problem, is not urgent.&amp;nbsp;I didn&amp;#39;t do any more research after implementing the delay, which was a good enough workaround for us to&amp;nbsp;continue the other work on the application.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/413645?ContentTypeID=1</link><pubDate>Mon, 06 Mar 2023 21:40:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e89950ce-7463-49a9-8188-9ad45b30fe36</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Sorry for the late reply. I have not been able to do my support work lately, and I am sorry for the inconvenience. I was about to look into this, but I wanted to check whether you had any findings in the last two weeks. If not, I will do some digging tomorrow.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/411534?ContentTypeID=1</link><pubDate>Thu, 23 Feb 2023 07:32:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:70d08eac-3548-43f3-8640-a9509138f039</guid><dc:creator>frankbuss</dc:creator><description>[quote userid="26071" url="~/f/nordic-q-a/96755/problem-with-subscription-notification/410801"]I see. Where did you see the callback that was discarded?[/quote]
&lt;p&gt;I think it was in att.c, in&amp;nbsp;bt_att_recv, because no handler was found.&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/96755/problem-with-subscription-notification/410801"]In the meantime, I guess a delay could work as a temporary workaround, just so that you don&amp;#39;t need to wait for this.[/quote]
&lt;p&gt;Thanks, I added one second delay, and looks like this works all the time. But it is not urgent, would be good to find a better solution.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/410982?ContentTypeID=1</link><pubDate>Tue, 21 Feb 2023 01:10:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33ca6ed3-4c79-4a83-9b28-778963187a0a</guid><dc:creator>frankbuss</dc:creator><description>&lt;p&gt;I created a&amp;nbsp;minimal test application, which demonstrates the problem:&lt;br /&gt;&lt;a id="" href="https://www.frank-buss.de/tmp/indicate_bug.zip"&gt;https://www.frank-buss.de/tmp/indicate_bug.zip&lt;/a&gt;&lt;br /&gt;You need to flash it on 2 nRF5340 DK boards. Then press button 1 on the first board, which connects with the second board, and will pair and save the bonding information. You can see that &amp;quot;counter received&amp;quot; counts from 1 to 10 (in a connected terminal to the 2nd UART). Then press reset&amp;nbsp;on the same board, and press the button 1 again. As you found out, the subscription information is restored, and the counter starts from 4 instead from 1.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/410801?ContentTypeID=1</link><pubDate>Mon, 20 Feb 2023 08:26:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2ce92ee-6105-45ae-ad0a-e8297c9d8f05</guid><dc:creator>Edvin</dc:creator><description>[quote user="frankbuss"]I debugged it, and could see in the Bluetooth stack on the&amp;nbsp;central side that the data arrived, but that it wasn&amp;#39;t forwarded to the application, because it thought it was not subscribed.[/quote]
&lt;p&gt;I see. Where did you see the callback that was discarded?&lt;/p&gt;
&lt;p&gt;I tried to reproduce this in the peripheral_uart and central_uart samples. I see that the callback is set in the discovery_complete event, but I am not sure whether the issue here is that discovery complete is called every time, and the callback is triggered from the central to set the notification callback. Could it be set elsewhere? I agree that the behavior is a bug, but I am not sure whether it is in the central gatt client implementation or in the bluetooth stack itself.&lt;/p&gt;
&lt;p&gt;Also, I am not sure whether the service discovery is actually happening if the device is bonded, or if it just returns discovery complete, just like the peripheral triggers the CCC changed callback. I will do some experimenting and capture some sniffer traces. I&amp;#39;ll try to get it done today, and I will update you.&lt;/p&gt;
&lt;p&gt;In the meantime, I guess a delay could work as a temporary workaround, just so that you don&amp;#39;t need to wait for this.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/410622?ContentTypeID=1</link><pubDate>Fri, 17 Feb 2023 12:06:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e642ba90-7507-406f-9ddb-715dc527839f</guid><dc:creator>frankbuss</dc:creator><description>&lt;p&gt;Right, looks like the status is restored immediately after a connect on the peripheral side. I think this is an architectural problem, because on the central side, the callback function is only set later with the&amp;nbsp;bt_gatt_subscribe function, and obviously this callback pointer can&amp;#39;t be saved. Meanwhile the peripheral has already sent data, which is then lost. I debugged it, and could see in the Bluetooth stack on the&amp;nbsp;central side that the data arrived, but that it wasn&amp;#39;t forwarded to the application, because it thought it was not subscribed.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve also compiled the central app for the posix target and ran it on Linux, with the hci_uart project for the Bluetooth part. I&amp;nbsp;then logged&amp;nbsp;the traffic with btmon, and looks like that I can see in Wireshark that the central device sends the subscription, see screenshot here:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/3286.bluetooth.png" /&gt;&lt;/p&gt;
&lt;p&gt;I&amp;nbsp;tested it with the&amp;nbsp;bt_gatt_is_subscribed functions, but looks like they return true as well immediately after a connect.&lt;/p&gt;
&lt;p&gt;I would appreciate any other idea. I guess as a workaround I could add a delay, but this wouldn&amp;#39;t be very elegant or reliable. I can also try to setup a&amp;nbsp;project to demonstrate the problem, but would be quite some work with the bonding etc.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/410573?ContentTypeID=1</link><pubDate>Fri, 17 Feb 2023 09:45:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4bbeacdf-8b37-43ba-b561-2bfe255c75a3</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;If you bond (store pairing information), then the status of the CCC (notification/indication) is stored, and will be restored the next time they connect.&lt;/p&gt;
&lt;p&gt;Otherwise, you can just monitor the return value from sending an indication to determine whether it is enabled or not, much like the peripheral_uart sample does when trying to send a notification using bt_nus_send(). It uses:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;else if (bt_gatt_is_subscribed(conn, attr, BT_GATT_CCC_NOTIFY)) {&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;to determine whether the central has enabled notifications or not.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Alternatively, you can try to capture a sniffer trace (&lt;a href="https://www.nordicsemi.com/Products/Development-tools/nrf-sniffer-for-bluetooth-le"&gt;nRF Sniffer for Bluetooth LE&lt;/a&gt;) to see whether the indication enable packet is actually sent on air or not.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/410432?ContentTypeID=1</link><pubDate>Thu, 16 Feb 2023 15:27:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a04fb75c-08e4-4ffa-bae2-efb0eb41ffed</guid><dc:creator>frankbuss</dc:creator><description>&lt;p&gt;I paired my&amp;nbsp;peripheral application with nRF Connect, and I can&amp;#39;t reproduce the problem either. So I guess something is wrong with my code for the central device. Will debug it in detail and then post the&amp;nbsp;solution (if I find one).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/410411?ContentTypeID=1</link><pubDate>Thu, 16 Feb 2023 14:47:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:451b7adf-3454-44ae-a77a-80bd171bcd27</guid><dc:creator>frankbuss</dc:creator><description>&lt;p&gt;I tried the&amp;nbsp;&lt;span&gt;zephyr/samples/bluetooth/peripheral_ht example, and can&amp;#39;t reproduce it. But indeed, the 2 devices in my application are paired. Could this be the reason?&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: problem with subscription notification</title><link>https://devzone.nordicsemi.com/thread/410394?ContentTypeID=1</link><pubDate>Thu, 16 Feb 2023 14:24:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:439de3c6-ce2d-4af0-b297-5095fe50b489</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;What is running on your central DK?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Does your application use bonding or pairing?&lt;/p&gt;
&lt;p&gt;Are you sure you are not triggering&amp;nbsp;&lt;span&gt;ccc_cfg_changed() from elsewhere? (accidentally putting it as your conneced callback?)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Is there a way for me to reproduce what you are seeing?&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;Edvin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>