<?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>Long running Android scanning in background.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/52773/long-running-android-scanning-in-background</link><description>I read the discussion in the following link, but my application is different so I want to ask for advice on how to proceed. 
 https://devzone.nordicsemi.com/f/nordic-q-a/50642/background-operation-of-ble-library-with-android-8---request-for-example 
</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 07 Dec 2019 20:21:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/52773/long-running-android-scanning-in-background" /><item><title>RE: Long running Android scanning in background.</title><link>https://devzone.nordicsemi.com/thread/224275?ContentTypeID=1</link><pubDate>Sat, 07 Dec 2019 20:21:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d64bb7f7-71ca-47fb-adf6-1cc45bd9ec7d</guid><dc:creator>Jason</dc:creator><description>&lt;p&gt;Hi Hung,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been busy creating a new Android+iOS app that uses google Flutter and google Firestore cloud backend. The cloud database overcomes the range problems I was having. My device is in direct body contact so it sometimes gets very low signal range due to the signal being absorbed by the body.&lt;/p&gt;
&lt;p&gt;I also made a new device prototype with&amp;nbsp;&lt;span&gt;the example provided in&amp;nbsp;&lt;strong&gt;examples\ble_peripheral\ble_app_hrs&lt;/strong&gt;.&amp;nbsp; I then made another version based on&amp;nbsp;&lt;/span&gt;&lt;strong&gt;examples\ble_peripheral\experimental\ble_app_multiperipheral. &lt;/strong&gt;&lt;span&gt;I&amp;nbsp;thought it would be nice to allow the device to maintain connections with several phones simultaneously, (it&amp;#39;s not crucial to the product.)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I notice the 2 examples are quite different. ble_app_hrs uses the advertising module (ble_advertising_init + peer manager etc) while the &lt;strong&gt;ble_app_multiperipheral &lt;/strong&gt;example&amp;nbsp;calls the soft device functions directly (sd_ble_gap_adv_start etc) . I&amp;#39;m not sure which is better to proceed with.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;The reason I am writing to you is because in your reply you said :-&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;strong&gt;&lt;em&gt;For example you can configure a connection with 0.5 second interval and 1 minutes timeout. You can configure the slave latency so that you only need to wakeup and response to the central every 30 seconds.&amp;nbsp;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Can you tell me what parameters I should use to get connections like this? Either for the ble_app_hrs example or for the bel_app_multiperipheral example (or another example!)&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been reading the design guidelines from Apple and the parameters seem crucial to achieving long battery life.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I assume I just need to set the right values for these #defines (from the ble_app_multiperipheral example)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define APP_ADV_INTERVAL                64                                      /**&amp;lt; The advertising interval (in units of 0.625 ms; this value corresponds to 40 ms). */
#define APP_ADV_DURATION                BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED   /**&amp;lt; The advertising duration (180 seconds) in units of 10 milliseconds. */

#define MIN_CONN_INTERVAL               MSEC_TO_UNITS(100, UNIT_1_25_MS)        /**&amp;lt; Minimum acceptable connection interval (0.5 seconds). */
#define MAX_CONN_INTERVAL               MSEC_TO_UNITS(200, UNIT_1_25_MS)        /**&amp;lt; Maximum acceptable connection interval (1 second). */
#define SLAVE_LATENCY                   0                                       /**&amp;lt; Slave latency. */
#define CONN_SUP_TIMEOUT                MSEC_TO_UNITS(4000, UNIT_10_MS)         /**&amp;lt; Connection supervisory time-out (4 seconds). */

#define FIRST_CONN_PARAMS_UPDATE_DELAY  APP_TIMER_TICKS(20000)                  /**&amp;lt; Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (15 seconds). */
#define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(5000)                   /**&amp;lt; Time between each call to sd_ble_gap_conn_param_update after the first call (5 seconds). */
#define MAX_CONN_PARAMS_UPDATE_COUNT    3                                       /**&amp;lt; Number of attempts before giving up the connection parameter negotiation. */





&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve already added some test code to create a timer to call advertising_start() intermittently. Assuming that this would be better than constant advertising. I was going to&amp;nbsp;set the timer to advertise once every 2 minutes just to avoid wasting energy but I&amp;#39;m not sure what is best. Any advice is greatly appreciated.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for your help&lt;/p&gt;
&lt;p&gt;-Jason&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long running Android scanning in background.</title><link>https://devzone.nordicsemi.com/thread/213068?ContentTypeID=1</link><pubDate>Wed, 02 Oct 2019 19:09:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:932ef15d-c99e-4b24-b612-275d728054db</guid><dc:creator>Jason</dc:creator><description>&lt;p&gt;Thank you for the excellent response. I&amp;nbsp;will begin making the necessary changes.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Long running Android scanning in background.</title><link>https://devzone.nordicsemi.com/thread/212844?ContentTypeID=1</link><pubDate>Tue, 01 Oct 2019 13:53:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24176919-4df4-46d1-a1a3-79724ec352e0</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Jason,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think keeping the device and the phone in connection could be a better idea. Scanning continuously (or with timing like what you described) consume the phone&amp;#39;s power. And on some phones with combo chip the antenna is shared between Wifi and Bluetooth making it harder to utilize two of them at the same time.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regarding your questions:&lt;/p&gt;
&lt;p&gt;1. Target the latest one, and set minimum to the lowest possible (depends on the features you use)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;2. Yes. Using a connection would be more stable and you can guarantee that the phone won&amp;#39;t kill the scanning service.&lt;/p&gt;
&lt;p&gt;For example you can configure a connection with 0.5 second interval and 1 minutes timeout. You can configure the slave latency so that you only need to wakeup and response to the central every 30 seconds. I think it would consume much less compare to your plan of sending 10 advertising packet every 2 minutes (each advertising event would require 3 packets sent)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Keeping a connection to a phone is quite basic and I don&amp;#39;t think you would have problem with most phones.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;3. I have forwarded your code to our app team, here is their feedback:&lt;/p&gt;
&lt;p&gt;Scanning is battery hungry on the phones as well. New Android versions don&amp;#39;t allow for long lasting background scan without a filter.&lt;/p&gt;
&lt;p&gt;Connection is much better approach for all use cases event determining location (beacons).&lt;/p&gt;
&lt;p&gt;Regarding his code:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use Service, not IntentService&lt;/li&gt;
&lt;li&gt;No need to keep the context, service IS a context&lt;/li&gt;
&lt;li&gt;With useHardwareBatchingIfSupported(false) they are not using offloaded batching, the library emulates it using cpu, which drains battery&lt;/li&gt;
&lt;li&gt;For bg scanning they should use low power mode, not low patency&lt;/li&gt;
&lt;li&gt;They should use scanning with an intent, not a callback.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;4. No. Better with scanning with an intent or at least a filter and low power mode. Newer phones may kill scanning after a few minutes.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>