Timmmm
Timmmm

Reputation: 96801

On Android 5.0 is it acceptable to continuously scan for BLE advertisements?

Suppose I need to detect a BLE advert that is only transmitted at 1 Hz for 60 seconds, and I don't know when in the day that will be. For this I need to scan continuously.

The official docs say

Because scanning is battery-intensive, you should observe the following guidelines:

  • As soon as you find the desired device, stop scanning.
  • Never scan on a loop, ...

But this excludes my use case.

The latest BLE chips (e.g. CC2560) use about 5 mA while scanning, which I assume is reduced on a duty cycle when using SCAN_MODE_LOW_POWER. My question is, if I use that mode, is it ok to just scan 24/7 (and inform the user)?

Also how does iOS do it for iBeacons?

Upvotes: 4

Views: 3703

Answers (3)

user2107373
user2107373

Reputation: 437

Unfortunately Android still has provided step motherly treatment to BLE stack. There is nothing in Android that can wakeup the app when a BLE device comes in proximity similar to what iOS 7+ provides.

We were optimistic that 5.0+ would have great enhancements but on the contrary it broke some of the existing functionality. Some devices like Nexus 4 and HTC One have such reduced scan activity after Android L update (discovers every 5-10 seconds even in low latency mode) that it makes it practically unusable for our use case.

So, the only solution is to continuously scan for BLE devices, which surely drains the battery. Depending on your use case, you can try some mechanism to stop scanning and start only when required. Like in our app, we used accelerometer to check when the phone is in movement. If the phone is not in movement, we stop the scan and start it again when the phone is moved.

Upvotes: 1

AAnkit
AAnkit

Reputation: 27549

On Android 5.0 is it acceptable to continuously scan for BLE advertisements?

It does not matter which Android version is it. It does totally depends on your implementation and user base. If you think you won't loose users if you continue scanning for the device, its ok to do it.

Also you can give parameters like low power, low frequency scanning in Android 5.1's BluetoothLEScanner, see ScanSettings.

You can also use filters on Android 5.1, which wont execute each piece of code(gatt, bluetoothService, frameworks, your app and many thing) for all available device but will let Bluetooth Gatt layer(and bluetooth Service, and your app) know if the device(you give it in filters) you are looking for is in vicinity. This filter is introduced to save some battery power in scanning time.

P.S:- I mentioned 5.1 everywhere as 5.0 bluetooth code sucks.

Upvotes: 3

mattm
mattm

Reputation: 5949

It sounds like you are stuck having to listen continuously to satisfy requirements. This is not ideal for power consumption reasons, as you have indicated.

Whether this is OK depends on how this is being used. Is this for a specific application with a known user base that needs this functionality and knows about the power hogging behavior? If so, it's probably OK. Is this for general users? No, this is not OK.

My understanding is that the iBeacon transmits every x seconds. For a receiver to hear all the iBeacons in an area, it needs to listen for only x seconds. In this design, both the beacons and the receivers can limit their power consumption.

The power consumption issue can be solved if you can change how the advertisements are sent, either by synchronizing when the transmitter and receiver go on, or by spreading out when the advertisements are sent.

Upvotes: 1

Related Questions