<?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>Subscribing to attributes in BLE service</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/118581/subscribing-to-attributes-in-ble-service</link><description>Hello! I am developing my own BLE solution where I have the different attributes in my service and I am connecting two different nrf52840, one to act as a GATTClient and one as a GATTServer The code below is for my client where I am discovering the service</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 25 Feb 2025 17:18:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/118581/subscribing-to-attributes-in-ble-service" /><item><title>RE: Subscribing to attributes in BLE service</title><link>https://devzone.nordicsemi.com/thread/524680?ContentTypeID=1</link><pubDate>Tue, 25 Feb 2025 17:18:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4469e2b0-efb0-4cc9-be0d-296c59d06151</guid><dc:creator>Menon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;You could refer to the sample central_uart, which I pointed out in my last response.&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Abhijith&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to attributes in BLE service</title><link>https://devzone.nordicsemi.com/thread/524379?ContentTypeID=1</link><pubDate>Mon, 24 Feb 2025 14:32:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c841293a-b981-4946-8ec0-eb01b9a9b4e5</guid><dc:creator>DevBear</dc:creator><description>&lt;p&gt;Thank you again! How do I even access the value_handle from the current CCCD? Is there some sample code where I can see an example of this since this:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;subscribe_params_txdata.value_handle = bt_gatt_attr_value_handle(attr);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Is not the correct approach&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;Bj&amp;ouml;rn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to attributes in BLE service</title><link>https://devzone.nordicsemi.com/thread/523075?ContentTypeID=1</link><pubDate>Fri, 14 Feb 2025 14:30:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:efadfc4b-2a36-405b-b386-0f3fb80dd4a8</guid><dc:creator>Menon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;In your code, you are using the &lt;code&gt;cccd_handle&lt;/code&gt; correctly, but you need to use the characteristic&amp;#39;s value handle for subscribing. When subscribing to a characteristic, you need to provide both.&lt;/p&gt;
&lt;p&gt;Refer to the&lt;a href="https://github.com/nrfconnect/sdk-nrf/tree/main/samples/bluetooth/central_uart"&gt; &lt;code&gt;central_uart&lt;/code&gt; sample&lt;/a&gt;, where you can find &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/main/samples/bluetooth/central_uart/src/main.c#L290"&gt;discovery_complete()&lt;/a&gt;. If you check&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/main/subsys/bluetooth/services/nus_client.c#L172"&gt; &lt;code&gt;bt_nus_subscribe_receive&lt;/code&gt;&lt;/a&gt; under&lt;a href="https://github.com/nrfconnect/sdk-nrf/tree/main/subsys/bluetooth/services"&gt; &lt;code&gt;nus_client.c&lt;/code&gt;,&lt;/a&gt; you will see how both of these values are used.&lt;/p&gt;
&lt;p&gt;For example: See&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/main/subsys/bluetooth/services/nus_client.c#L182"&gt; line 18&lt;/a&gt;2, that is the characteristic&amp;#39;s value handle. If you check &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/main/subsys/bluetooth/services/nus_client.c#L183"&gt;line 183&lt;/a&gt;, that is the &lt;code&gt;cccd_handle&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Kind Regards,&lt;/p&gt;
&lt;p&gt;Abhijith&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to attributes in BLE service</title><link>https://devzone.nordicsemi.com/thread/522443?ContentTypeID=1</link><pubDate>Tue, 11 Feb 2025 13:18:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:454e6733-8299-4860-98a7-6217c2ce26c7</guid><dc:creator>DevBear</dc:creator><description>&lt;p&gt;Why should I store the characteristics handle when the original code from one of the samples does like what I am doing?&lt;/p&gt;
&lt;p&gt;And&amp;nbsp;which handle is that exactly if I shouldn&amp;#39;t store the value_handle? Is it the ccc_handle?&lt;br /&gt;Isn&amp;#39;t it like the code I have in the original snippet from row 62 onwards? Isn&amp;#39;t that the correct subscription methodology?&lt;/p&gt;
&lt;p&gt;With the exception that I am only subscribing to one of the cccd:s at the moment?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Bj&amp;ouml;rn&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to attributes in BLE service</title><link>https://devzone.nordicsemi.com/thread/521505?ContentTypeID=1</link><pubDate>Wed, 05 Feb 2025 10:09:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:62ac2602-e279-4a74-b4de-d44a5bcb8ac2</guid><dc:creator>Menon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;You need to create a &lt;code&gt;bt_gatt_subscribe_params&lt;/code&gt; for each CCCD and call &lt;code&gt;bt_gatt_subscribe()&lt;/code&gt;. From the initial code you shared, it looks like you&amp;#39;re only discovering the CCCD descriptors but never actually subscribing after discovery.&lt;/p&gt;
&lt;p&gt;Your &lt;code&gt;discover_func()&lt;/code&gt; should first find all the handles and then subscribe &lt;i&gt;only&lt;/i&gt; after the discovery is complete. Also, &lt;code&gt;value_handle&lt;/code&gt; should be the characteristic&amp;#39;s value handle, not the descriptor&amp;#39;s handle.&lt;/p&gt;
&lt;p&gt;Instead of setting &lt;code&gt;subscribe_params.value_handle&lt;/code&gt; like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;subscribe_params.value_handle = bt_gatt_attr_value_handle(attr);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You should store the characteristic&amp;#39;s handle when you find it.&lt;/p&gt;
&lt;p&gt;Kind Regards,&lt;/p&gt;
&lt;p&gt;Abhijith&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to attributes in BLE service</title><link>https://devzone.nordicsemi.com/thread/521339?ContentTypeID=1</link><pubDate>Tue, 04 Feb 2025 14:38:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:77bfe0ab-b036-445a-9236-1d4f8b2ff656</guid><dc:creator>DevBear</dc:creator><description>&lt;p&gt;Hello!&amp;nbsp;&lt;br /&gt;Already find all the CCCD descriptors and the characteristics, I need to subscribe to them and I don&amp;#39;t know how to add that when I have two different sets of CCCDs and characteristics.&lt;br /&gt;&lt;br /&gt;The question is fairly straight forward, if I have the code I have given in my post. In these two sections:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;} else if (!bt_uuid_cmp(discover_params.uuid, BT_UUID_RXCREDIT)) {
		printk(&amp;quot;Discovering CCC TxData\n&amp;quot;);
		//memcpy(&amp;amp;frog_discover_uuid, BT_UUID_GATT_CCC, sizeof(frog_discover_uuid));
		discover_params.uuid = ccc_uuid;
		ccc_uuid2 = ccc_uuid;
		discover_params.start_handle = attr-&amp;gt;handle + 2;
		discover_params.type = BT_GATT_DISCOVER_DESCRIPTOR;
		subscribe_params.value_handle = bt_gatt_attr_value_handle(attr);

		err = bt_gatt_discover(conn, &amp;amp;discover_params);
		if (err) {
			printk(&amp;quot;Discover failed (err %d)\n&amp;quot;, err);
		}
	} else if (!bt_uuid_cmp(discover_params.uuid, ccc_uuid2)){
		printk(&amp;quot;Discovering CCC RxCredit\n&amp;quot;);
		//memcpy(&amp;amp;frog_discover_uuid, BT_UUID_GATT_CCC, sizeof(frog_discover_uuid));
		discover_params.uuid = ccc_uuid;
		discover_params.start_handle = attr-&amp;gt;handle + 2;
		discover_params.type = BT_GATT_DISCOVER_DESCRIPTOR;
		subscribe_params.value_handle = bt_gatt_attr_value_handle(attr);

		err = bt_gatt_discover(conn, &amp;amp;discover_params);
		if (err) {
			printk(&amp;quot;Discover failed (err %d)\n&amp;quot;, err);
		}
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Do I need to add subscribing within each of those blocks? Or should it be done outside of those blocks?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Subscribing to attributes in BLE service</title><link>https://devzone.nordicsemi.com/thread/521293?ContentTypeID=1</link><pubDate>Tue, 04 Feb 2025 12:09:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:23095701-d034-46a3-a58a-2a6b98b836bb</guid><dc:creator>Menon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I recommend including logs to verify and handle the discovery. You first need to discover the characteristic, then find the CCCD descriptor, and finally subscribe to notifications. You can follow &lt;a href="https://academy.nordicsemi.com/courses/bluetooth-low-energy-fundamentals/lessons/lesson-4-bluetooth-le-data-exchange/topic/blefund-lesson-4-exercise-2/"&gt;this exercise from the Developer Academy course,&lt;/a&gt; which discusses something very similar.&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Abhijith&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>