<?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>How to discover a service, disconnect from it and discover another one ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/123352/how-to-discover-a-service-disconnect-from-it-and-discover-another-one</link><description>Hello, 
 I&amp;#39;m working on Windows 11, with the nRF Connect for VS Code v2025.5.512 extension, with ncs v3.0.2. I&amp;#39;m using the nRF54L15-dk (PCA10156; 0.9.2; 2025.7) development kits. 
 So, I want to use the channel sounding sample to measure a distance and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 03 Sep 2025 09:13:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/123352/how-to-discover-a-service-disconnect-from-it-and-discover-another-one" /><item><title>RE: How to discover a service, disconnect from it and discover another one ?</title><link>https://devzone.nordicsemi.com/thread/547588?ContentTypeID=1</link><pubDate>Wed, 03 Sep 2025 09:13:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d2f6600-3d68-4951-9654-4c9c8c0729b8</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Sorry for the late reply.&lt;/p&gt;
&lt;p&gt;Yes. I noticed the reboots, since the boot banner was being printed repeatedly as well.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user="Patrick49"]But I want to scan again without rebooting my device[/quote]
&lt;p&gt;You want to scan what? Do another distance measurement? Or do you want to use the custom service?&lt;/p&gt;
&lt;p&gt;You already have all the handles (I presume). So why can&amp;#39;t you just use them?&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: How to discover a service, disconnect from it and discover another one ?</title><link>https://devzone.nordicsemi.com/thread/545928?ContentTypeID=1</link><pubDate>Mon, 18 Aug 2025 12:54:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:881ab617-913b-41c7-a8a8-e1ab7e5104ab</guid><dc:creator>Patrick49</dc:creator><description>&lt;p&gt;Hello Edvin,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yes, I have the same log on the initiator. Now you&amp;#39;re seeing that I&amp;#39;m using the reboot function in order to start a new scan after a 5 seconds&amp;#39; delay. But I want to scan again without rebooting my device since it consumes some power. How can I achieve that ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Patrick&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to discover a service, disconnect from it and discover another one ?</title><link>https://devzone.nordicsemi.com/thread/545927?ContentTypeID=1</link><pubDate>Mon, 18 Aug 2025 12:46:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e7beb0e-2f3b-4e66-9240-25794cc3022a</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Running your applications, this is what I see in the initiator&amp;#39;s log:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting nRF Connect SDK v3.0.2-89ba1294ac9b ***
*** Using Zephyr OS v4.0.99-f791c49f492c ***
I: Starting Channel Sounding Initiator Sample
I: SoftDevice Controller build revision:
I: 89 9a 50 8a 95 01 9c 58 |..P....X
I: fc 39 d2 c1 10 04 ee 02 |.9......
I: 64 ce 25 be             |d.%.
I: HW Platform: Nordic Semiconductor (0x0002)
I: HW Variant: nRF54Lx (0x0005)
I: Firmware: Standard Bluetooth controller (0x00) Version 137.20634 Build 2617349514
I: Identity: F7:36:2B:14:6E:A9 (random)
I: HCI: version 6.0 (0x0e) revision 0x30f3, manufacturer 0x0059
I: LMP: version 6.0 (0x0e) subver 0x30f3
I: NUS Client module initialized
I: Filters matched. Address: E8:85:AF:8C:2B:33 (random) connectable: 1
I: Connecting
I: Connected to E8:85:AF:8C:2B:33 (random) (err 0x00)
I: Security changed: E8:85:AF:8C:2B:33 (random) level 2
I: MTU exchange success (498)
I: Discovery completed for RANGING service (context == NULL)
I: CS capability exchange completed.
I: CS config creation complete. ID: 0
I: CS security enabled.
I: CS procedures enabled successfully
I: Application completed its workflow
I: CS procedures enabled:
 - config ID: 0
 - antenna configuration index: 0
 - TX power: -16 dbm
 - subevent length: 28198 us
 - subevents per event: 1
 - subevent interval: 0
 - event interval: 2
 - procedure interval: 10
 - procedure count: 0
 - maximum procedure length: 1000
I: Distance estimates : ifft: 0.585532
I: Device is close enough, initiating CUS discovery
Starting CUSTOM discovery
 I: CS procedures disabled.
I: Discovery completed for CUSTOM service
[SUBSCRIBED]
Confirmation received : 1234
Write success !
I: All operations complete, disconnecting...
I: Disconnected (reason 0x16)
W: opcode 0x2094 status 0x02
Cycle connection-disconnection : 4307 ms&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And this is repeating forever.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is not what you are seeing if you run it on 2x nRF54l15DKs?&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to discover a service, disconnect from it and discover another one ?</title><link>https://devzone.nordicsemi.com/thread/545556?ContentTypeID=1</link><pubDate>Wed, 13 Aug 2025 14:33:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54fce853-72a5-4eeb-8a23-b17bbcaa3719</guid><dc:creator>Patrick49</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/CS3_5F00_prog.zip"&gt;devzone.nordicsemi.com/.../CS3_5F00_prog.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hello Edvin,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;By the application, you meant both programs with the initiator and reflector ?&amp;nbsp;&lt;br /&gt;If yes, here is in the CS3_prog.zip both of them that I&amp;#39;m using on two nRF54L15-dk.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I tried putting the security changed in the connected_cb function with the init_channel_sounding function after the first iteration but it didn&amp;#39;t work. It still block after the second connection was done.&amp;nbsp;&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/123352/how-to-discover-a-service-disconnect-from-it-and-discover-another-one/545542"]You still shouldn&amp;#39;t need to disconnect -&amp;gt; reconnect in order to use other services[/quote]
&lt;p&gt;And no, I&amp;#39;m not disconnecting to discover both services, I followed the central_uart and the peripheral_ancs sample (to discover two services one after the other) and adapted it for my application.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Patrick&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to discover a service, disconnect from it and discover another one ?</title><link>https://devzone.nordicsemi.com/thread/545542?ContentTypeID=1</link><pubDate>Wed, 13 Aug 2025 13:40:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d083733-5e39-4bad-b490-8a1c923d4d28</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Patrick,&lt;/p&gt;
&lt;p&gt;Can you please upload your current application, so that I can have a look, and reproduce the issue that you are seeing?&lt;/p&gt;
&lt;p&gt;My initial guess is that it is waiting for the &amp;quot;Security Changed&amp;quot; event, which never occurs, but without seeing your application, it is difficult to say.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You still shouldn&amp;#39;t need to disconnect -&amp;gt; reconnect in order to use other services, but I am not really sure what your application looks like at this point, or what it is trying to do.&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: How to discover a service, disconnect from it and discover another one ?</title><link>https://devzone.nordicsemi.com/thread/545386?ContentTypeID=1</link><pubDate>Tue, 12 Aug 2025 13:03:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba479f0e-7471-4867-a1a9-dd17f654249f</guid><dc:creator>Patrick49</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/CS2_5F00_prog.zip"&gt;devzone.nordicsemi.com/.../CS2_5F00_prog.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hello Edvin,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So I implemented your solution and it works for the first loop.&lt;br /&gt;But, when the initiator is scanning for the second time, it&amp;#39;s blocking here :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1755003498109v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve tried a lot of things but I can&amp;#39;t get it to work. I have linked my new program in the attached documents.&amp;nbsp;&lt;br /&gt;It&amp;#39;s working well if I reboot my device instead of scanning again in the disconnected_cb but I want to be able to not use the reboot since it consumes a lot.&lt;/p&gt;
&lt;p&gt;If you have any suggestion on how to solve my problem, it would be very helpful !&lt;/p&gt;
&lt;p&gt;Thanks and best regards,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Patrick&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to discover a service, disconnect from it and discover another one ?</title><link>https://devzone.nordicsemi.com/thread/544552?ContentTypeID=1</link><pubDate>Tue, 05 Aug 2025 06:48:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:539181c3-f04f-4671-8c69-f4e4cb2e5286</guid><dc:creator>Patrick49</dc:creator><description>&lt;p&gt;Hello Edvin,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for the answer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve actually done it by moving my distance measurement and the discovery call in the callback function to register when the data is ready, that is to say in&amp;nbsp;ranging_data_get_complete_cb().It seems to work fine. I&amp;#39;ll consider your solution if something breaks.&lt;/p&gt;
&lt;p&gt;Best regards,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Patrick&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to discover a service, disconnect from it and discover another one ?</title><link>https://devzone.nordicsemi.com/thread/544193?ContentTypeID=1</link><pubDate>Thu, 31 Jul 2025 10:20:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6912ca2b-6481-4f12-bbd6-bdd71e8cf327</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Looking at your cs_initiator5.c, it seems like you start the discovery process in your connected_cb() function.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Your question is a bit diffuse to me. Your peripheral (reflector) should contain all the services and characteristics at all times. But it is up to your applications when you want to use them. When you connect, start the service discovery, which should store all the characteristic handles.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I see that you are using bt_gatt_discover() directly. This is possible, but perhaps you should consider using bt_gatt_dm_start() instead, which is a bit more abstracted. This is used in the NCS\nrf\samples\bluetooth\central_uart sample. Then you will get a discovery complete callback:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void discovery_complete(struct bt_gatt_dm *dm,
			       void *context)
{
	struct bt_nus_client *nus = context;
	LOG_INF(&amp;quot;Service discovery completed&amp;quot;);

	bt_gatt_dm_data_print(dm);

	bt_nus_handles_assign(dm, nus);
	bt_nus_subscribe_receive(nus);

	bt_gatt_dm_data_release(dm);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you initialize the discovery parameters with service UUID = NULL, it will give you a callback for each service. So you just add handlers for all characteristics that you want to use, that checks if it is the correct service, and if so, register the handle. E.g. if you want to register the NUS (Nordic uart service) and an additional service called &amp;quot;CUS&amp;quot; (Custom service), you can have something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void discovery_complete(struct bt_gatt_dm *dm,
			       void *context)
{
	struct bt_nus_client *nus = context;
	LOG_INF(&amp;quot;Service discovery completed&amp;quot;);

	bt_gatt_dm_data_print(dm);

	bt_nus_handles_assign(dm, nus);
	bt_nus_subscribe_receive(nus);
	bt_cus_handles_assign(dm, cus);
	bt_cus_subscribe_receive(cus);

	bt_gatt_dm_data_release(dm);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can see in the implementation of e.g. bt_nus_handles_assign() in nus_client.c that the first thing it does is checking the UUID:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int bt_nus_handles_assign(struct bt_gatt_dm *dm,
			  struct bt_nus_client *nus_c)
{
	const struct bt_gatt_dm_attr *gatt_service_attr =
			bt_gatt_dm_service_get(dm);
	const struct bt_gatt_service_val *gatt_service =
			bt_gatt_dm_attr_service_val(gatt_service_attr);
	const struct bt_gatt_dm_attr *gatt_chrc;
	const struct bt_gatt_dm_attr *gatt_desc;

	if (bt_uuid_cmp(gatt_service-&amp;gt;uuid, BT_UUID_NUS_SERVICE)) {
		return -ENOTSUP;
	}
	...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And returns if the UUID is not the BT_UUID_NUS_SERVICE, so when it is called on another service that is discovered, it will just ignore that service.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Once all your services are discovered, you can use them from wherever you prefer in your application.&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: How to discover a service, disconnect from it and discover another one ?</title><link>https://devzone.nordicsemi.com/thread/544117?ContentTypeID=1</link><pubDate>Wed, 30 Jul 2025 14:37:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7a17774-c640-4ebd-99e5-903b7281ddcf</guid><dc:creator>Patrick49</dc:creator><description>&lt;p&gt;Hello Edvin,&lt;/p&gt;
&lt;p&gt;Thanks for the answer:&lt;/p&gt;
&lt;p&gt;In my program, I&amp;#39;m chaining the service and characteristics discoveries like that : ranging service -&amp;gt; custom service -&amp;gt; write characteristic -&amp;gt; confirm characteristic for the notification. So how can I switch from the ranging service to my custom when the distance is below a certain threshold ? Maybe it&amp;#39;s due to the call of discover_custom_service() function that is misplaced in my program ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Indeed, I don&amp;#39;t think I need to disconnect from the first service to my custom one.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know if my problem is clearer for you, now ?&lt;/p&gt;
&lt;p&gt;Best regards,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Patrick&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to discover a service, disconnect from it and discover another one ?</title><link>https://devzone.nordicsemi.com/thread/544103?ContentTypeID=1</link><pubDate>Wed, 30 Jul 2025 13:35:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:067ac621-3b4b-45d0-bf5f-17014683edda</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Patrick&lt;/p&gt;
[quote user=""]So my question is how to discover a service, disconnect from it and discover another one ?[/quote]
&lt;p&gt;There is no need to disconnect from the device to discover other services.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is it so that you have both the services working as it should in different applications? If so, look at how the service discovery is done in them. Try combining the two into the same central application.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Service discovery should only be done once per connection, and you can trigger it in the connected callback event, like it is done in most of our central application samples (e.g. using gatt_discover() in our central_uart sample).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Then, you can use your application logic to start sending notifications from the peripheral to the central whenever the distance is low enough.&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></channel></rss>