<?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>Cannot remove the custom service</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/68282/cannot-remove-the-custom-service</link><description>MCU: nRF 52832 SDK VERSION: 17.0.0_9d13099 SOFTDEVICE: 7.0.1 (s132) 
 I have an application with some custom services (4) with different characteristics number and behavior (read/write/notify) and everything works just fine. The problem started when I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 12 Nov 2020 13:27:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/68282/cannot-remove-the-custom-service" /><item><title>RE: Cannot remove the custom service</title><link>https://devzone.nordicsemi.com/thread/279739?ContentTypeID=1</link><pubDate>Thu, 12 Nov 2020 13:27:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d05e9728-17c3-4a08-9553-c5d67ccccd28</guid><dc:creator>Cwanci</dc:creator><description>[quote userid="7377" url="~/f/nordic-q-a/68282/cannot-remove-the-custom-service/279737#279737"]Ah, I see. Then this is probably the phone caching the services.[/quote]
&lt;p&gt;Wrong guess&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f609.svg" title="Wink"&gt;&amp;#x1f609;&lt;/span&gt; As I mentioned before:&amp;nbsp;&lt;/p&gt;
[quote userid="12476" url="~/f/nordic-q-a/68282/cannot-remove-the-custom-service/279725#279725"]&lt;p&gt;I thought that maybe I need to reset BLE dongle and NRF connect but it didn&amp;#39;t help me at all.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;I am using USB dongle and NRF Connect for desktop all the time . I don&amp;#39;t quite&amp;nbsp;trust mobile app... to be honest &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt; So as I mentioned I thought maybe I need to delete bond information or just replug dongle and reset NRFConnect. Didn&amp;#39;t help. Full chip erase deleted bonds in the device and reset app deleted bonds in it. I guess it must be something else.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for responses anyway. It works as I wanted so I moving forward. But I&amp;#39;ll keep in mind to investigate this further in the future.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot remove the custom service</title><link>https://devzone.nordicsemi.com/thread/279737?ContentTypeID=1</link><pubDate>Thu, 12 Nov 2020 13:21:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3bf6535c-0571-4916-a464-7940cb55549a</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="Cwanci"]I get this error in NRF Connect app, when I click &amp;quot;Connect&amp;quot; button. The device doesn&amp;#39;t connect or rather connects and disconnects&amp;nbsp;immediately and I get this popup.&amp;nbsp;[/quote]
&lt;p&gt;Ah, I see. Then this is probably the phone caching the services. I expect you would see that things work as expected if you use for instance nRF Connect for desktop (no caching behind the scenes) or change the BLE address of the nRF so that the phone would see it as a new device. You could also try to toggle bluetooth off and on in the phone, though if and how that works differ a bit.&lt;/p&gt;
[quote user="Cwanci"] thought that when I comment the StsInit line and erase memory + program this code, the SoftDevice would be &amp;quot;reinitialized&amp;quot; without this service.[/quote]
&lt;p&gt;Yes, that is the case.&lt;/p&gt;
[quote user="Cwanci"]None. Everything works as I want, but I wanted to understand why it doesn&amp;#39;t work with simple StsInit removal and e.g. disconnecting power from the board.&amp;nbsp;[/quote]
&lt;p&gt;Must be phone caching, but as mentioned you can easily confirm by using nrf connect for desktop.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot remove the custom service</title><link>https://devzone.nordicsemi.com/thread/279732?ContentTypeID=1</link><pubDate>Thu, 12 Nov 2020 13:16:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:117e261d-29d1-4b47-a618-b4143a983620</guid><dc:creator>Cwanci</dc:creator><description>[quote userid="7377" url="~/f/nordic-q-a/68282/cannot-remove-the-custom-service/279728#279728"]This error: &amp;quot;Failed to get services (BLE_ERROR_INVALID_CONN_HANDLE).&amp;quot;? Where do you get this error?[/quote]
&lt;p&gt;I get this error in NRF Connect app, when I click &amp;quot;Connect&amp;quot; button. The device doesn&amp;#39;t connect or rather connects and disconnects&amp;nbsp;immediately and I get this popup.&amp;nbsp;&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/68282/cannot-remove-the-custom-service/279728#279728"]I see. This makes sense. If you do not add the service, it does not show (as expected). What is the problem with this? Again, if the service is there it absolutely must be because you configure it. So to not have the service you need to make sure to not run the code that adds it. Once added, the only way to remove it is to re-initialize the SoftDevice (typically after a reset).[/quote]
&lt;p&gt;I thought that when I comment the StsInit line and erase memory + program this code, the SoftDevice would be &amp;quot;reinitialized&amp;quot; without this service. This service isn&amp;#39;t added in any other code line - only StsInit which calls ble_sts_init. As you see in ble_sts_init service is enabled and characteristics are added.&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/68282/cannot-remove-the-custom-service/279728#279728"]What is the problem with this?[/quote]
&lt;p&gt;None. Everything works as I want, but I wanted to understand why it doesn&amp;#39;t work with simple StsInit removal and e.g. disconnecting power from the board.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot remove the custom service</title><link>https://devzone.nordicsemi.com/thread/279728?ContentTypeID=1</link><pubDate>Thu, 12 Nov 2020 13:07:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5537eed9-efc7-4dbe-972a-37e3b64bbe81</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="Cwanci"]Thanks for reply. As I mentioned, I&amp;#39;ve even fully erased chip and programmed everything again with commented initialization line. The same result. I thought that maybe I need to reset BLE dongle and NRF connect but it didn&amp;#39;t help me at all.&amp;nbsp;[/quote]
&lt;p&gt;As mentioned none of this really matters, as everything is configured again when the SoftDevice is configured. It does not &amp;quot;remember&amp;quot; previous configuration, services etc. As long as you reset the device, the new configuration will be whatever your current firmware configures regardless of what was there before. However, phones etc. will cache a lot of information so you cannot rely on that. Therefore I was very interested in knowing how you see that old services are still there?&amp;nbsp;But reading your last post I suspect an issue with your code.&lt;/p&gt;
[quote user="Cwanci"]As for your question. When I&amp;#39;ve commented &amp;quot;StsInit&amp;quot; in code I couldn&amp;#39;t connect to the device due to mentioned error. [/quote]
&lt;p&gt;&amp;nbsp;This error: &amp;quot;Failed to get services (BLE_ERROR_INVALID_CONN_HANDLE).&amp;quot;? Where do you get this error?&lt;/p&gt;
[quote user="Cwanci"]&lt;p&gt;When I want to start application in mode 2 I just init this service with false parameter.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So, if I enable mode 1 I can see standard services like BAS, DIS and my 4 custom services. When I enter mode 2 I see only BAS, DIS and 1 of my custom services. This is exactly what I wanted to achieve but I don&amp;#39;t quite understand why I have to do it that way so this lead me to ask this question&lt;/p&gt;[/quote]
&lt;p&gt;I see. This makes sense. If you do not add the service, it does not show (as expected). What is the problem with this? Again, if the service is there it absolutely must be because you configure it. So to not have the service you need to make sure to not run the code that adds it. Once added, the only way to remove it is to re-initialize the SoftDevice (typically after a reset).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot remove the custom service</title><link>https://devzone.nordicsemi.com/thread/279725?ContentTypeID=1</link><pubDate>Thu, 12 Nov 2020 12:57:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:986d21a7-2e4c-4fcf-aeb9-c10eaa724737</guid><dc:creator>Cwanci</dc:creator><description>&lt;p&gt;Hello.&lt;/p&gt;
&lt;p&gt;Thanks for reply. As I mentioned, I&amp;#39;ve even fully erased chip and programmed everything again with commented initialization line. The same result. I thought that maybe I need to reset BLE dongle and NRF connect but it didn&amp;#39;t help me at all.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As for your question. When I&amp;#39;ve commented &amp;quot;StsInit&amp;quot; in code I couldn&amp;#39;t connect to the device due to mentioned error. The only way working for me in this moment is to call StsInit with bool parameter which is passed to ble_sts_init. The code looks like below.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t ble_sts_init(ble_sts_t * p_sts, const ble_sts_init_t * p_sts_init, bool enableService){
	if (p_sts == NULL || p_sts_init == NULL){
		return NRF_ERROR_NULL;
	}
	uint32_t   err_code;
	ble_uuid_t ble_uuid;

	// Initialize service structure
	p_sts-&amp;gt;conn_handle = BLE_CONN_HANDLE_INVALID;
	p_sts-&amp;gt;evt_handler = p_sts_init-&amp;gt;evt_handler;

	//TODO workaround to be changed later
	if (!enableService)
		return NRF_SUCCESS;

	// Add Status Service UUID
	ble_uuid128_t base_uuid = {STATUS_SERVICE_UUID_BASE};
	err_code =  sd_ble_uuid_vs_add(&amp;amp;base_uuid, &amp;amp;p_sts-&amp;gt;uuid_type);
	VERIFY_SUCCESS(err_code);
	ble_uuid.type = p_sts-&amp;gt;uuid_type;
	ble_uuid.uuid = STATUS_SERVICE_UUID;

	// Add the Status Service
	err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &amp;amp;ble_uuid, &amp;amp;p_sts-&amp;gt;service_handle);
	if (err_code != NRF_SUCCESS){
		return err_code;
	}
	// Add the States Characteristic
	err_code = sts_status_char_add(p_sts,p_sts_init);
	if (err_code != NRF_SUCCESS){
		return err_code;
	}
	// Add the Errors Characteristic
	err_code = sts_error_char_add(p_sts, p_sts_init);
	if (err_code != NRF_SUCCESS){
		return err_code;
	}

	return NRF_SUCCESS;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;When I want to start application in mode 2 I just init this service with false parameter.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So, if I enable mode 1 I can see standard services like BAS, DIS and my 4 custom services. When I enter mode 2 I see only BAS, DIS and 1 of my custom services. This is exactly what I wanted to achieve but I don&amp;#39;t quite understand why I have to do it that way so this lead me to ask this question :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot remove the custom service</title><link>https://devzone.nordicsemi.com/thread/279718?ContentTypeID=1</link><pubDate>Thu, 12 Nov 2020 12:47:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c04ec70c-f563-46c0-80b3-e4ba08c7b985</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]This produces the result I wanted - the service isn&amp;#39;t visible. My question is - why simply removing StsService_init() from code doesn&amp;#39;t work? Why do I have to do special workaround? If i comment line 9 and 10 in ble_sts_init it will also produce error.&amp;nbsp;[/quote]
&lt;p&gt;You always start with an empty set of services etc when you initialize the SoftDevice. If you do not add a service/characteristic/anything, it will not be there. Also, there is no way to remove a service from the SoftDevice without re-enabling it.&lt;/p&gt;
&lt;p&gt;I would be interesting in knowing how you find that the service has not been removed? The only two reasons I can think of without knowing more is that either the peer has cached the services and therefor you think they are still there even though they are not, or that you have some code that runs and adds the service(s) even that you have somehow missed. I do not see anything in what you write or your small code snippets that indicate the latter, though.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>