<?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>Disabling the advertising and scanning by a short press of a button and re-enabling it by pressing the same button again.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/85871/disabling-the-advertising-and-scanning-by-a-short-press-of-a-button-and-re-enabling-it-by-pressing-the-same-button-again</link><description>Hello Team, I hope you will be fine. 
 We are working on a project where we integrated multiple libraries from different projects. We are using soft devices too. Now I want to put the device in sleep mode(all the other events should turn off except the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 21 Mar 2022 13:13:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/85871/disabling-the-advertising-and-scanning-by-a-short-press-of-a-button-and-re-enabling-it-by-pressing-the-same-button-again" /><item><title>RE: Disabling the advertising and scanning by a short press of a button and re-enabling it by pressing the same button again.</title><link>https://devzone.nordicsemi.com/thread/359143?ContentTypeID=1</link><pubDate>Mon, 21 Mar 2022 13:13:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6292b335-ea2c-417e-9720-08d6642fcc52</guid><dc:creator>Sami Ul Haq</dc:creator><description>&lt;p&gt;Sir, I have resolved the issue. Thank you so much for your help.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Sami Ul Haq&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disabling the advertising and scanning by a short press of a button and re-enabling it by pressing the same button again.</title><link>https://devzone.nordicsemi.com/thread/359137?ContentTypeID=1</link><pubDate>Mon, 21 Mar 2022 13:05:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c8b0d1a-fe74-4873-b2bb-d390fa37adae</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I see you opened a &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/85996/how-to-disconnect-central-mobile-app-from-nrf52-both-central-and-peripheral-using-ble_app_hrs_rscs_relay-example"&gt;new thread&lt;/a&gt; about this so we will continue there.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disabling the advertising and scanning by a short press of a button and re-enabling it by pressing the same button again.</title><link>https://devzone.nordicsemi.com/thread/359050?ContentTypeID=1</link><pubDate>Mon, 21 Mar 2022 09:37:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54b0b6d8-92a5-4827-82e2-d0b610b4f120</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Sami,&lt;/p&gt;
&lt;p&gt;Looking at your second code snippet, let me clarify one thing. sd_ble_gap_disconnect() is used to disconnect connections. It is wrong to try to use this to stop advertising or scanning. To stop advertising, you call sd_ble_gap_adv_stop(), and do stop scaning, call nrf_ble_scan_stop(), as you do. So remove the two sd_ble_gap_disconnect() calls you have there.&lt;/p&gt;
&lt;p&gt;However, if you have a connection you want to terminate you should call sd_ble_gap_disconnect() with the connection handle of the connection (which you got from the BLE_GAP_EVT_CONNECTED event). I do not see that anywhere in your code snippet, but that is what you need to do.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disabling the advertising and scanning by a short press of a button and re-enabling it by pressing the same button again.</title><link>https://devzone.nordicsemi.com/thread/358766?ContentTypeID=1</link><pubDate>Fri, 18 Mar 2022 07:16:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e75f5be7-2a5d-4d36-9089-600a61fe18c6</guid><dc:creator>Sami Ul Haq</dc:creator><description>&lt;p&gt;Hello Einar, Thanks for the reply.&lt;/p&gt;
&lt;p&gt;Yes, I am observing behaviour in debugging as you can see in the below attached picture.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x136/__key/communityserver-discussions-components-files/4/polar_5F00_disconnect.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;before the short press of a button, the Polar H10 is connected and I can see the Heart Rate in debugging, but when I short press the button, it disconnects the Polar H10 and I can no longer see Heart Rate in debugging. When I long-press the same button and call&amp;nbsp;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;scan_init()&amp;nbsp;&lt;/strong&gt;&lt;span&gt;and&amp;nbsp;&lt;/span&gt;&lt;strong&gt;scan_start(),&amp;nbsp;&lt;/strong&gt;the Heart Rate doesn&amp;#39;t re-appear in the debug. In the below pictures you can see my disconnect functions.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/short_5F00_press.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;As you can see in the above picture(which is for short press) I am calling two disconnect functions one for scanning and the other for advertising. The scanned device(Polar H10) got disconnected and the advertised device(Mobile App) doesn&amp;#39;t, even I change&amp;nbsp;the &lt;strong&gt;ble_adv_on_disconnect_disabled == true&amp;nbsp;&lt;/strong&gt;in ble_advertising.c as per your suggestion. Maybe I am not passing the correct parameter in the disconnect function for disconnecting the advertised device, please check it I am using the&amp;nbsp;&lt;strong&gt;ble_app_hrs_rscs_relay&amp;nbsp;&lt;/strong&gt;example.&lt;/p&gt;
&lt;p&gt;The below picture is the code for a long press of the same button where I want to wake the device that is to start advertising, scanning etc and come back to normal functions(wake).&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/long_5F00_press.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;Kind Regards,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sami Ul Haq&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disabling the advertising and scanning by a short press of a button and re-enabling it by pressing the same button again.</title><link>https://devzone.nordicsemi.com/thread/358673?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2022 13:33:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c5a4008-f925-4236-adb9-176bb84abc22</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="Sami Ul Haq"]after a long press but it does not re-connect the peripheral (Polar H10). I don&amp;#39;t know why?[/quote]
&lt;p&gt;I suggest you debug / perhaps add some logging to se what is happening.&lt;/p&gt;
[quote user="Sami Ul Haq"]One more problem is that I am unable to even disconnect the central like Mobile app by calling&amp;nbsp;&lt;strong&gt;sd_ble_gap_discon&lt;/strong&gt;&lt;strong&gt;nect()&amp;nbsp;&lt;/strong&gt;after a short pressing of a button.&amp;nbsp;[/quote]
&lt;p&gt;As long as you call&amp;nbsp;sd_ble_gap_disconnect() with the correct connection handle, the connection will be disconnected. However, if you are using the advertising module it will automatically start advertise again upon disconnecting (see implementation of&amp;nbsp;on_disconnected() in&amp;nbsp;components\ble\ble_advertising\ble_advertising.c). So you you need to change the configuration to prevent that, by setting config.ble_adv_on_disconnect_disabled to true&amp;nbsp; in the&amp;nbsp;ble_advertising_init_t instance you provide to the call to&amp;nbsp;ble_advertising_init().&lt;/p&gt;
[quote user="Sami Ul Haq"]I am doing exactly the same but unable to re-connect the peripheral(Polar H10). And the mobile app is even not disconnected after calling the disconnect function.[/quote]
&lt;p&gt;I see. In that case you need to debug to understand what is actually happening first.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disabling the advertising and scanning by a short press of a button and re-enabling it by pressing the same button again.</title><link>https://devzone.nordicsemi.com/thread/358667?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2022 13:25:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8ef180ba-72c5-4056-9d19-f3acd1149442</guid><dc:creator>Sami Ul Haq</dc:creator><description>&lt;p&gt;Hello Einar, Thank you for your precious reply.&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/85871/disabling-the-advertising-and-scanning-by-a-short-press-of-a-button-and-re-enabling-it-by-pressing-the-same-button-again/358655#358655"]What you are describing here is exactly what system ON mode is for. But you must yourself disable advertising, turn off the GPS, etc. When you stop everything, but RAM is still powered and RTC is running, that is system on low power mode.[/quote]
&lt;p&gt;Yes, sir, I knew that and the RTC is not a problem for us it should be ON.&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/85871/disabling-the-advertising-and-scanning-by-a-short-press-of-a-button-and-re-enabling-it-by-pressing-the-same-button-again/358655#358655"]Stopping to scan is separate from stopping to advertise, which in turn is separate from disconnecting a connection. If you also want to disconnect an active connection upon a button press, you need to do that. For that, you use&amp;nbsp;sd_ble_gap_disconnect().[/quote]
&lt;p&gt;Yes sir, I just studied that today and understand the difference between &amp;nbsp;&lt;strong&gt;sd_ble_gap_adv_stop()&amp;nbsp;&lt;/strong&gt;and&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;sd_ble_gap_disconnect().&amp;nbsp;&lt;/strong&gt;I can now successfully stop scanning and disconnect the peripheral like the &lt;strong&gt;Polar H10 sensor&lt;/strong&gt; by pressing a button but I am unable to reconnect it by long-pressing the same button. I am calling&amp;nbsp;&lt;strong&gt;scan_init()&amp;nbsp;&lt;/strong&gt;and &lt;strong&gt;scan_start()&amp;nbsp;&lt;/strong&gt;after a long press but it does not re-connect the peripheral (Polar H10). I don&amp;#39;t know why?&lt;/p&gt;
&lt;p&gt;One more problem is that I am unable to even disconnect the central like Mobile app by calling&amp;nbsp;&lt;strong&gt;sd_ble_gap_discon&lt;/strong&gt;&lt;strong&gt;nect()&amp;nbsp;&lt;/strong&gt;after a short pressing of a button.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can you please help me with these problems.?&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/85871/disabling-the-advertising-and-scanning-by-a-short-press-of-a-button-and-re-enabling-it-by-pressing-the-same-button-again/358655#358655"]If you disconnected and stopped advertising etc. on the first button press and want to be able to connect again on the second button press that means you need to start connectable advertising on the second button press. So in this case, if you are using something similar to SDK examples which use the advertising library, you call&amp;nbsp;ble_advertising_start() when you want to start advertising again. That way a central can connect. If you also implement central features and want to start scanning and connect, you do that. There is nothing special in this case, just that incidentally you use a button press to trigger this instead of some other event (or simply doing it at startup).[/quote]
&lt;p&gt;I am doing exactly the same but unable to re-connect the peripheral(Polar H10). And the mobile app is even not disconnected after calling the disconnect function.&lt;/p&gt;
&lt;p&gt;Kind Regards,&lt;/p&gt;
&lt;p&gt;Sami Ul Haq&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disabling the advertising and scanning by a short press of a button and re-enabling it by pressing the same button again.</title><link>https://devzone.nordicsemi.com/thread/358655?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2022 13:02:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63dd08cd-6deb-4331-857f-89c6ddeea3c6</guid><dc:creator>Einar Thorsrud</dc:creator><description>[quote user="Sami Ul Haq"]But I read in the power management tutorial that in&amp;nbsp;&lt;strong&gt;System ON mode&lt;/strong&gt; the device wakes on every event like advertising, scanning,&amp;nbsp;RTC etc.&amp;nbsp;which we don&amp;#39;t want. We want that when we press a button and the device closes all its activities like scanning, advertising, GPS etc. (only RTC is running as we don&amp;#39;t want that the device time to be disturbed). In short that we want that by pressing a button the device got shutdown artificially( like turning OFF a television from remote not from the power switch) and only RTC is running, So we have to manually close all the activities except RTC.&amp;nbsp;[/quote]
&lt;p&gt;What you are describing here is exactly what system ON mode is for. But you must yourself disable advertising, turn off the GPS, etc. When you stop everything, but RAM is still powered and RTC is running, that is system on low power mode.&lt;/p&gt;
[quote user="Sami Ul Haq"]Yes, that&amp;#39;s true that the device goes to sleep in between the advertising, but the advertising interval is short and more important there is scanning all the time which cannot be avoided and it will consume a lot of power.[/quote]
&lt;p&gt;The SoftDevice BLE will do what it is configured to do. Scanning and advertising can be avoided. If you don&amp;#39;t want do do it for a period after a button press, then stop doing theseactivities when you get the button press.&lt;/p&gt;
[quote user="Sami Ul Haq"]Yes, sir, I used that API and it is stopping advertising, and&amp;nbsp;&lt;strong&gt;nrf_ble_scan_stop();&amp;nbsp;&lt;/strong&gt;stop scanning but once I connected to the peripheral like Polar H10 or central like mobile App then I was unable to disconnect from it by pressing a button.[/quote]
&lt;p&gt;Stopping to scan is separate from stopping to advertise, which in turn is separate from disconnecting a connection. If you also want to disconnect an active connection upon a button press, you need to do that. For that, you use&amp;nbsp;sd_ble_gap_disconnect().&lt;/p&gt;
[quote user="Sami Ul Haq"]And if for example if I disconnect from the peripheral then I am unable to re-connect again by pressing the same button again for waking of the device.&amp;nbsp;[/quote]
&lt;p&gt;If you disconnected and stopped advertising etc. on the first button press and want to be able to connect again on the second button press that means you need to start connectable advertising on the second button press. So in this case, if you are using something similar to SDK examples which use the advertising library, you call&amp;nbsp;ble_advertising_start() when you want to start advertising again. That way a central can connect. If you also implement central features and want to start scanning and connect, you do that. There is nothing special in this case, just that incidentally you use a button press to trigger this instead of some other event (or simply doing it at startup).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disabling the advertising and scanning by a short press of a button and re-enabling it by pressing the same button again.</title><link>https://devzone.nordicsemi.com/thread/358522?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2022 05:10:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5cf6bfc9-a5d8-4371-8960-27f3b97b0b55</guid><dc:creator>Sami Ul Haq</dc:creator><description>&lt;p&gt;Hello Einar,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/85871/disabling-the-advertising-and-scanning-by-a-short-press-of-a-button-and-re-enabling-it-by-pressing-the-same-button-again/358433#358433"]Which SDK are you using?[/quote]
&lt;p&gt;nRF5_SDK_17.0.2&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/85871/disabling-the-advertising-and-scanning-by-a-short-press-of-a-button-and-re-enabling-it-by-pressing-the-same-button-again/358433#358433"]I believe this is wrong. System ON is typically used for exactly these kinds of use cases,&amp;nbsp;where the device sleeps for most of the time (in system ON mode) consuming&amp;nbsp; a few micro amps, and wakes up whenever there is work to do and goes back to sleep. For this reason, virtually all nRF applications use system ON low power mode as much as possible.[/quote]
&lt;p&gt;But I read in the power management tutorial that in&amp;nbsp;&lt;strong&gt;System ON mode&lt;/strong&gt; the device wakes on every event like advertising, scanning,&amp;nbsp;RTC etc.&amp;nbsp;which we don&amp;#39;t want. We want that when we press a button and the device closes all its activities like scanning, advertising, GPS etc. (only RTC is running as we don&amp;#39;t want that the device time to be disturbed). In short that we want that by pressing a button the device got shutdown artificially( like turning OFF a television from remote not from the power switch) and only RTC is running, So we have to manually close all the activities except RTC.&amp;nbsp;&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/85871/disabling-the-advertising-and-scanning-by-a-short-press-of-a-button-and-re-enabling-it-by-pressing-the-same-button-again/358433#358433"] A key point here is that the device is sleeping also while advertising, in between advertising events. It is not so that the CPU is active all the time doing nothing (this would be fundamentally the wrong approach for a low power design).[/quote]
&lt;p&gt;As you said the device will wake on the mentioned events and it will then perform events like Advertising, Scanning etc. and will consume a lot of power as the device is scanning continuously all the time.&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/85871/disabling-the-advertising-and-scanning-by-a-short-press-of-a-button-and-re-enabling-it-by-pressing-the-same-button-again/358433#358433"]A key point here is that the device is sleeping also while advertising, in between advertising events. It is not so that the CPU is active all the time doing nothing (this would be fundamentally the wrong approach for a low power design).[/quote]
&lt;p&gt;Yes, that&amp;#39;s true that the device goes to sleep in between the advertising, but the advertising interval is short and more important there is scanning all the time which cannot be avoided and it will consume a lot of power.&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/85871/disabling-the-advertising-and-scanning-by-a-short-press-of-a-button-and-re-enabling-it-by-pressing-the-same-button-again/358433#358433"]Generally, it is your responsibility to stop whatever you are doing that consumes power before entering sleep mode. There are generally API calls for things, like stopping advertising. This depends on SDK, but if you are for instance using the nRF5 SDK you typically call sd_ble_gap_adv_stop() to stop advertising. And similar for other activities. Then entering sleep mode is done &amp;quot;automatically&amp;quot;, by calling __WFE() in the main loop or idle thread. [/quote]
&lt;p&gt;Yes, sir, I used that API and it is stopping advertising, and&amp;nbsp;&lt;strong&gt;nrf_ble_scan_stop();&amp;nbsp;&lt;/strong&gt;stop scanning but once I connected to the peripheral like Polar H10 or central like mobile App then I was unable to disconnect from it by pressing a button. I want that when I press a button and the &lt;strong&gt;NRF52&lt;/strong&gt; got disconnected from peripheral and central and stop scanning and advertising as well. And if for example if I disconnect from the peripheral then I am unable to re-connect again by pressing the same button again for waking of the device.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks and Regards,&lt;/p&gt;
&lt;p&gt;Sami Ul Haq&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disabling the advertising and scanning by a short press of a button and re-enabling it by pressing the same button again.</title><link>https://devzone.nordicsemi.com/thread/358433?ContentTypeID=1</link><pubDate>Wed, 16 Mar 2022 12:51:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:227e7ceb-526a-4b69-b0b8-4cf9fd1ad341</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Which SDK are you using?&lt;/p&gt;
[quote user=""]The problem is that we cannot use a simple &lt;strong&gt;system on sleep mode&lt;/strong&gt; because we have the GPS Data which is 10 samples per second and will wake the device almost all the time and consume a lot of power.[/quote]
&lt;p&gt;I believe this is wrong. System ON is typically used for exactly these kinds of use cases,&amp;nbsp;where the device sleeps for most of the time (in system ON mode) consuming&amp;nbsp; a few micro amps, and wakes up whenever there is work to do and goes back to sleep. For this reason, virtually all nRF applications use system ON low power mode as much as possible.&lt;/p&gt;
[quote user=""]we cannot use the &lt;strong&gt;system off mode&lt;/strong&gt; as the device gets reset after that which we don&amp;#39;t want.[/quote]
&lt;p&gt;I agree. System OFF mode is not suitable in this case.&lt;/p&gt;
&lt;p&gt;Basically, system ON mode just means that the CPU enters idle mode. And that is done by most SDK examples, and it wakes up on RTC when there is an event that has been scheduled (for instance a radio event of some sort, or some other application event, like reading data from a GPS). A key point here is that the device is sleeping also while advertising, in between advertising events. It is not so that the CPU is active all the time doing nothing (this would be fundamentally the wrong approach for a low power design).&lt;/p&gt;
&lt;p&gt;Generally, it is your responsibility to stop whatever you are doing that consumes power before entering sleep mode. There are generally API calls for things, like stopping advertising. This depends on SDK, but if you are for instance using the nRF5 SDK you typically call sd_ble_gap_adv_stop() to stop advertising. And similar for other activities. Then entering sleep mode is done &amp;quot;automatically&amp;quot;, by calling __WFE() in the main loop or idle thread. If you are using BLE in the nRF5 SDK, you typically call sd_app_evt_wait(), either directly or via a library. If you are not using it, you may call it directly yourself (refer to an example). If using the nRF Connect SDK, the idle thread will call __WFE() for you.&lt;/p&gt;
&lt;p&gt;If you want to wake up on a button press, you configure interrupt on a GPIO pin (see relevant example for the SDK you are using).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>