<?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>Notify battery level without active subscription</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/121248/notify-battery-level-without-active-subscription</link><description>Hello, 
 we are developing a device which implements BLE hid keyboard. The code is based on the hid keyboard example in the NRF Connect SDK. 
 The example uses battery service (bas.h and bas.c) to notify client about battery level percentage. 
 The problem</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 15 May 2025 13:26:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/121248/notify-battery-level-without-active-subscription" /><item><title>RE: Notify battery level without active subscription</title><link>https://devzone.nordicsemi.com/thread/535611?ContentTypeID=1</link><pubDate>Thu, 15 May 2025 13:26:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68965e4f-d989-4a33-b641-435eac86d0e9</guid><dc:creator>Evgeny M</dc:creator><description>&lt;p&gt;disagree :), because the specification allows this scenario, but Zephyr API does not implement it. But I feel that this will be a tough discussion if I bring it up to Zephyr community. We will stay with the hack for now.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Notify battery level without active subscription</title><link>https://devzone.nordicsemi.com/thread/535593?ContentTypeID=1</link><pubDate>Thu, 15 May 2025 12:48:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d138bc49-5872-4e91-8dd4-07d23f85e5ee</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Then that is an issue that needs to be fixed on the android side, everything else will be a hack.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Notify battery level without active subscription</title><link>https://devzone.nordicsemi.com/thread/535564?ContentTypeID=1</link><pubDate>Thu, 15 May 2025 12:12:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3cbeb4b-cbb2-47ae-8bc7-cfb2b3061a7b</guid><dc:creator>Evgeny M</dc:creator><description>&lt;p&gt;it&amp;#39;s not lost. If I subscribe in the NRF Connect App, the notifications are coming through also after reconnect. So it looks like in the nRF stack everything is fine.&lt;/p&gt;
&lt;p&gt;The problem is that Android manages keyboard connection natively. You don&amp;#39;t need an app for that. And it seems that it does not subscribe automatically, it only reads the value once upon connect. So if you stay connected for a long time, which is normal for a keyboard, you don&amp;#39;t see the actual battery level.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Notify battery level without active subscription</title><link>https://devzone.nordicsemi.com/thread/535516?ContentTypeID=1</link><pubDate>Thu, 15 May 2025 10:23:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2955c481-75f8-47df-a4c1-73d17c48f506</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Honestly I do not see a significant need for this feature, I can only think of having seend discussions about this a handfull of times over qutie a few years. As mentionned, this is in no way a normal thing to do, and there is likely another issue in your use case that shoudl be adressed in a different way. So instead of focusing on this I would recomend backtracking a bit to understand how the devices end up in a state where notifications are no longer enabled in the CCCD for some reason. Is the database locally on the nRF somehow not persisstent, so tha teven if a bonded peer has enabled notifications, this is not remembered for the next connection, or is something else not going as planned? Or is the state lost somewhere else?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Notify battery level without active subscription</title><link>https://devzone.nordicsemi.com/thread/535450?ContentTypeID=1</link><pubDate>Thu, 15 May 2025 06:57:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:786e0ec8-08de-4e85-86c5-72561e70a543</guid><dc:creator>Evgeny M</dc:creator><description>&lt;p&gt;Thank you for the constructive response. Maybe it also makes sense to modify Zephyr API, because using only k_config is not that flexible because it changes behavior for all kinds of notifications. Imagine some sensor, for example temperature sensor. The client can decide whether it receives notifications periodically or it actively reads the temperature characteristic. But the low battery notification could be done without subscription because it triggers not that often and it is critical.&lt;/p&gt;
&lt;p&gt;So instead of configuration variable it can be a parameter in gatt notify* functions, whether to honor the subscription or not. Then the server can decide on each notification individually.&lt;/p&gt;
&lt;p&gt;&lt;span class="HwtZe" lang="en"&gt;&lt;span class="jCAhz ChMk0b"&gt;&lt;span class="ryNqvb"&gt;Do you think this is worth bringing up for discussion in the Zephyr community or is this proposal not in line with how it is done in Bluetooth?&lt;/span&gt;&lt;/span&gt; &lt;span class="jCAhz"&gt;&lt;span class="ryNqvb"&gt;Because I am quite new to Bluetooth development.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Notify battery level without active subscription</title><link>https://devzone.nordicsemi.com/thread/535320?ContentTypeID=1</link><pubDate>Wed, 14 May 2025 12:18:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e9672409-5ea7-4d7d-80fa-12a07f6591f2</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I see your point. I am not&amp;nbsp;making&amp;nbsp;CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION chagne the behaviour like that is desierable. Perhaps another/new configuration parameter could be used to say that not only should notify without subscription be allowed, but it should be the default? I have forwarded this internally, but I cannot say if and when there will be any changes on this (thsi is also direclty from Zephyr, so any potential change here would have to be&amp;nbsp;in by the Zephyr project).&lt;/p&gt;
&lt;p&gt;Edit: To be clear, this means that any potential changes here would be unlikely and not happen shortly, so this would have to be solved either by you modifying the SDK, or better, understanding the root cause of this issue. To understand the issue, if you could start from scratch and show sniffer traces where the CCCD is enabled and notifications are sent, and explain and show with thraces the behaviour where this is soemthow lost, we could digg into that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Notify battery level without active subscription</title><link>https://devzone.nordicsemi.com/thread/534948?ContentTypeID=1</link><pubDate>Mon, 12 May 2025 15:56:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5f5512e-60a4-4fa1-8add-abc857191880</guid><dc:creator>Evgeny M</dc:creator><description>&lt;p&gt;Hello Einar, thank you for the clarification,&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/121248/notify-battery-level-without-active-subscription/534701"]I woudl also consider backtracking and looking into why you need such an unusual approach, could it be that this could be solved in another way?[/quote]
&lt;p&gt;I only found an advice to delete the bond, reboot the phone and try to pair again &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/115191/battery-service-notification"&gt;devzone.nordicsemi.com/.../battery-service-notification&lt;/a&gt;. In my case the service was already present from the beginning of the development, still I tried to reboot, but it did not help.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/121248/notify-battery-level-without-active-subscription/534701"]it is not obvious that bt_gatt_notify(_cb) shoudl notify peers that do not subscribe to the characteristic, as it is normally not needed, and it is not unlikely for a multi connection device to be connected to both devices that subscrib and not (and those who do not subscribe, do not want it[/quote]
&lt;p&gt;I think, if the device behavior is to notify without subscription, then it should be the same for all connected peers. This simply means that the client does have to subscribe explicitly.&lt;/p&gt;
&lt;p&gt;Besides, the bluetooth specification does not require mandatory subscription. It&amp;#39;s up to the server to decide if notification should be sent or not&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Notify battery level without active subscription</title><link>https://devzone.nordicsemi.com/thread/534701?ContentTypeID=1</link><pubDate>Fri, 09 May 2025 14:07:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78edf0c1-b0d1-4954-a8b5-27057bc30893</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I see. The&amp;nbsp;CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION configuration can be used to disable checking of enabled notifications so the stack allows it, but it would be up to you to make other changes. I see your point, but allowing this would not be the same as enforcing it (it is not obvious that bt_gatt_notify(_cb) shoudl notify peers that do not subscribe to the characteristic, as it is normally not needed, and it is not unlikely for a multi connection device to be connected to both devices that subscrib and not (and those who do not subscribe, do not want it).&lt;/p&gt;
&lt;p&gt;What you want is quite unusuall, so any handling of this would have to specifically adress your use case without negatively affecting othere more common ones. (I woudl also consider backtracking and looking into why you need such an unusual approach, could it be that this could be solved in another way?)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Notify battery level without active subscription</title><link>https://devzone.nordicsemi.com/thread/534323?ContentTypeID=1</link><pubDate>Wed, 07 May 2025 15:13:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:87907462-deca-45b6-a4d5-97eff6ac0e05</guid><dc:creator>Evgeny M</dc:creator><description>&lt;p&gt;&amp;gt; The problem is that the battery level is transmitted only when the connection is established.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;sorry, bad wording. I mean that it is sent once at the moment when the devices get connected after the advertising. If I call bas_notify() later, while the connection is already on for a while, the notification is not sent.&lt;/p&gt;
&lt;p&gt;&amp;gt; Obviously Android phone which I use for tests does not subscribe for this notification.&lt;/p&gt;
&lt;p&gt;I mean it does not do this automatically. But as I mentioned, it is possible to do in the NRF Connect App by clicking on the &amp;quot;three arrows icon&amp;quot;. But this is not the use case we are planning.&lt;/p&gt;
&lt;p&gt;&amp;gt; So for some reason ccc.cfg array contains invalid data.&lt;/p&gt;
&lt;p&gt;&amp;gt; In what way is it invalid? Can you elaborate? Also, can you share the changes you did to the sample and instructions on &amp;gt; how to reproduce so I can test this on my end?&lt;/p&gt;
&lt;p&gt;I checked the source code again, this was premature to say that it&amp;#39;s invalid :) I guess these lines are exactly the condition that checks whether the client is subscribed or not. I was confused by the field names.&lt;/p&gt;
&lt;p&gt;So the problem is actually that the function notify_cb() in gatt.c does not take into account the value of CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION. Is it possible that you add this in the next version of SDK?&lt;/p&gt;
&lt;p&gt;If you confirm that this is a problem, I think there is not need to prepare an example to reproduce the issue.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m attaching the modified hid.c. There are many other changes (it uses message queue to communicate with the main thread), so it will be difficult to use it directly in the example.&lt;/p&gt;
&lt;p&gt;The relevant change is in the function bas_notify(), specifically I pass the active connection to bt_bas_set_battery_level(), which was modified in tthe SDK folder (the code is in the previous message).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/hid.c"&gt;devzone.nordicsemi.com/.../hid.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Notify battery level without active subscription</title><link>https://devzone.nordicsemi.com/thread/534290?ContentTypeID=1</link><pubDate>Wed, 07 May 2025 13:14:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e00598a-3cae-4a0a-8583-9697a053fabb</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am not sure I understand the issue her, so I have some questions.&lt;/p&gt;
[quote user=""]The problem is that the battery level is transmitted only when the connection is established. [/quote]
&lt;p&gt;Notifications can only be send when a connection is active. Can you elaborate on what you mean here?&lt;/p&gt;
[quote user=""]Obviously Android phone which I use for tests does not subscribe for this notification.[/quote]
&lt;p&gt;Why does it not? If the GATT client want notifications from a characteristic, it shoudl enable it in the CCCD. This is the normal behaviour (thoguh as you have seen, it is also legal to sent notifications even though not enabled,&amp;nbsp;though that is not common).&lt;/p&gt;
[quote user=""]So for some reason ccc.cfg array contains invalid data.[/quote]
&lt;p&gt;In what way is it invalid? Can you elaborate? Also, can you share the changes you did to the sample and instructions on how to reproduce so I can test this on my end?&lt;/p&gt;
[quote user=""]This works but changing the SDK files is not the best idea.[/quote]
&lt;p&gt;It is good that works, but as you say it is not ideal, and it really should not be needed,&amp;nbsp;so we should get to the bottom of this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>