<?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 stop advertising BLE</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/102928/cannot-stop-advertising-ble</link><description>Hi, 
 
 I&amp;#39;m using S132 SoftDevice on the nRF52832 custom board. The SDK version is nRF5_SDK_17.1.0_ddde560. 
 Firstly, I have these functions to terminate the BLE connection and terminate the BLE advertising. 
 
 My advertising config defines init.config</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 18 Aug 2023 07:15:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/102928/cannot-stop-advertising-ble" /><item><title>RE: Cannot stop advertising BLE</title><link>https://devzone.nordicsemi.com/thread/442011?ContentTypeID=1</link><pubDate>Fri, 18 Aug 2023 07:15:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fa002744-a6f1-4909-9bd4-71e89503af1e</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Xander,&lt;/p&gt;
[quote user="Xander To"]However, isn’t it weird that the board crash when I change the BLe status code? Can it be possible?[/quote]
&lt;p&gt;It depends on what you mean by &amp;quot;crash&amp;quot; and what actually happens with the board. Withoug debugging we don&amp;#39;t know what is happening, but most likely there is a good explanation. So I am looking forward to seeing what you find from debugging (starting with the error code).&lt;/p&gt;
[quote user="Xander To"]&lt;strong&gt;UPDATE:&lt;/strong&gt; After a bit of testing, I believe calling the advertising_stop() to soon after disconnectBLE() can cause advertising not to be stopped. Therefore, I change the advertise config to not advertise after disconnect and restart advertising wherever I want.[/quote]
&lt;p&gt;Sounds good, that is a much better approach in this case (automatically re-starting advertising mostly makes sense if you always want to start advertising after a disconnect).&lt;/p&gt;
&lt;p&gt;Br,&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot stop advertising BLE</title><link>https://devzone.nordicsemi.com/thread/441919?ContentTypeID=1</link><pubDate>Thu, 17 Aug 2023 15:23:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2de5b0ec-4af1-443d-bc6f-3ce0b2356c2f</guid><dc:creator>Xander To</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;I will check the error code once we get a J-Link/DK to debug as I&amp;rsquo;m working on a custom board at the moment. However, isn&amp;rsquo;t it weird that the board crash when I change the BLe status code? Can it be possible?&lt;/p&gt;
&lt;p&gt;Regarding the advertising issue, the advertising_stop is called after the disconnection is executed, so I still don&amp;rsquo;t understand why BLE is still advertised. Does it mean I call this function to fast and the disconnectBLE function doesn&amp;rsquo;t have enough time to actually disconnect BLE and start advertising BLE?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; After a bit of testing, I believe calling the advertising_stop() to soon after disconnectBLE() can cause advertising not to be stopped. Therefore, I change the advertise config to not advertise after disconnect and restart advertising wherever I want.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Xander&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot stop advertising BLE</title><link>https://devzone.nordicsemi.com/thread/441866?ContentTypeID=1</link><pubDate>Thu, 17 Aug 2023 12:39:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a63fd820-3b18-460c-ac30-036bf47855d4</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Xander,&lt;/p&gt;
[quote user=""]However, the board crashes when it encounters the APP_ERROR_CHECK line of disconnectBLE function. Therefore, I removed the APP_ERROR_CHECK line. I know this is not good but just for testing. This time, the board doesn&amp;#39;t terminate the BLE and the board doesn&amp;#39;t crash of course.[/quote]
&lt;p&gt;This indicates that the &amp;quot;crash&amp;quot; was that&amp;nbsp;APP_ERROR_CHECK() was called with an error code. Have you checked what the error code was? A simple way to do it could be to enable debug logging (enable logging, and build with DEBUG and DEBUG_NRF enabled). Or just inspect from a debugger.&lt;/p&gt;
&lt;p&gt;Also, sometimes it can be OK to ignore an error, but then that specific error should be handled explicitly, and you should know why you get it and why it is OK to ignore it (the same way as you do with&amp;nbsp;NRF_ERROR_INVALID_STATE).&lt;/p&gt;
[quote user=""]Secondly, the advertising_stop() function doesn&amp;#39;t stop advertising after a disconnection as I can still scan for its BLE after the board terminates the connection. Did I do it incorrectly?[/quote]
&lt;p&gt;Based on what you write, the advertising module should be configured to start advertising after a connection is terminated. And that will happen even if you have stopped advertising before (while a connection was active). So you would have to stop advertising again. Or change your approach and set&amp;nbsp;ble_adv_on_disconnect_disabled to true, and handle starting of advertising after disconnects yourself (to only do it when you want to).&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>