I have a working BLE scanning app that has been working fine for last few months on Nexus 5 (on various API versions from 4.4 to 6.0 ). Today we ran the app on different device "Huawei Ascend Mate2" that has API 22 and found what I thought was an interesting or peculiar behavior: callback gets fired continuously (about thrice a second), but my iBeacon is detected in only one callback and in remaining callbacks it picks other devices in the house (like netgear router and roku etc; I donot know if this netgear and rouku are even BLE devices).
My BLE scanning code is very similar to the one described here http://www.truiton.com/2015/04/android-bluetooth-low-energy-ble-example/
This thread
Android 4.4 BLE Scanning lack of stability suggests that BLE scanning is stable on 5.0+, but in my case that is not true because I am on API 22
This thread
Android BLE Beacon scanning on different phone models suggests that we need to turn on and turnoff the scanning every 1.5 seconds and that is not practical in our use case because our app should run for 10 hours every day (we think starting/stopping of system resource is expensive operation)
I am puzzled on why the same beacon is getting detected in continuous callbacks on Nexus 5 (tested on both 4.4 and 6.0 Android APIs); but when running on "Huawei Ascend Mate2", though callback is continuously invoked, the same iBeacon is detected only once while other non BLE devices are detected in subsequent callbacks.
This is the first time I tested outside Nexus. Did anyone test BLE scanning on "Huawei Ascend Mate2"? Any observations and comments would be appreciated.
"Huawei Ascend Mate2": Device model number is MT2L03 and Android version is 5.1
I worked with a lot of different devices and I can tell you, that the behaviour is very different on different devices. I don't have an Huawei Mate2, but I could observe similar behaviour, where you only get a scan result once per device. So if you need to have multiple scan result for the same device you need to restart the scan from time to time. I think 1.5s is a bit too much, but this depends on your use case.
Related
My issue is that iOS and various android phones receive number of BLE advertise packet from specific ibeacon, for example In 5 minutes from a specific beacon iOS receives about 904 advertise packets and android phones receive about between 230 to 480 depending on the phone.
Does anyone know if there is a setting that can set scanning rate of the BLE module? If not what else might cause this issue?
I use "CBCentralManager" to utilize BLE module in iOS and "blutoothLeScanner" in Android.
//Creating an instance of CBCentralManager
private let bluetoothManager = CBCentralManager(delegate: nil, queue: nil)
//Start Scanning
bluetoothManager.scanForPeripherals(withServices: nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey:NSNumber(value: true)])
The scan parameters are hardcoded in both OSs, but on Android you can choose between the following three modes:
https://developer.android.com/reference/android/bluetooth/le/ScanSettings.html#SCAN_MODE_BALANCED
https://developer.android.com/reference/android/bluetooth/le/ScanSettings.html#SCAN_MODE_LOW_LATENCY
https://developer.android.com/reference/android/bluetooth/le/ScanSettings.html#SCAN_MODE_LOW_POWER
Note that if you scan in the background, SCAN_MODE_LOW_POWER will be used regardless of what you select.
There is a large amount of variation between Android device models (often called fragmentation) and this applies to the Bluetooth LE behavior as much as anything. Differences between Android phones is a more likely explanation for the discrepancies you see than the scan rate, which defaults to a 100% duty cycle (LOW LATENCY) on all Android devices I have seen, and is similar to iOS.
Given the same conditions, some Android devices scan a similar number of BLE advertisements in iPhones (e.g. Pixel and later Nexus 5+ devices.) But not all Android devices provide as good of results.
You don't say specifically which Android models that you tested which saw fewer advertisement detections, but there are a number of things that might cause this:
Some older Android devices like the Nexus 4, Nexus 7 and Moto G (1st generation) would only detect on advertisement per scan per unique bluetooth device. Restarting the scan was needed to detect a second packet from that device. You might try restarting your BLE scan every second or so to see if this helps.
Some Android devices like the Huawei P9 have very poorly performing BLE antennas, so they are rarely able to detect BLE devices at more than 10 meters, whereas iPhones typically detect at 40-50 meters or more. You can see if this is the cause of your issue by looking at the signal level (RSSI value) for packets received. Are the RSSI values consistently weaker (more negative) on the Android device vs. iOS? If so, then this explains the discrepancy.
I know the same behaviour from some phones.
Note that your peripheral probably does advertising on 3 BLE channels. (?) It might be possible that your Android device only listens on one channel.
Moreover and on some cases even worse, it is possible that your phones listens on one channel at a time and another channel some time later, thus, also does channel hopping for scanning. It is possible that you get aliasing effects and see the advertising only a few times. This is why the Apple Accessory Guide recommends certain advertising intervals of the peripheral. (chap. 23.5)
I have developed an application that needs to run a continuous BLE scanning, because it has to check that all the surrounding peripherals are transmitting.
When one or more of them stop transmitting, my app must raise an alert.
I've tested it on some phones:
1 - Samsung Note 4 with Android 5.1.1
2 - Honor 8 with Android 6.0
3 - LG Nexus 5 with Android 6.0.1
4 - Samsung Note 4 with Android 6.0.1
5 - Samsung J5 with Android 6.0.1
ONLY ON PHONES 4 and 5, the discovery of BLE peripherals seems to behave differently when the device is "awake" compared to when it's locked.
In particular, when I press the power button and the device goes to locked state, the phone stops discovering my peripherals - or at least, discovery is triggered at a very low frequency. When I press the power button again (going back to unlocked mode by entering a pin), BLE discovery starts again and runs continuously.
The service that operates the scan is perfectly alive and running, but simply it does not perform the scan.
This strange behaviour is only happening on phones 4 and 5 (Samsung with Android 6.0.1). Same phone with different android version, and same android version on different phones seem not to be affected.
I've tried various workarounds, without success:
Disable Android Doze Mode for my application, both from Android Settings and from source code in my app
Using various ScanSettings options: ScanMode, NumOfMatches, MatchMode…
Giving the scan service a high wake-lock level
Has anybody ever had the same problem?
EDIT: tested and ok also on Samsung Note 2 with Android 4.4.2
This may be linked to the location service going into a low-priority state. You may try turning the services to high accuracy in the test devices and re-test.
I'm trying to communicate two smartphones with Android 5.x through BLE.
First of all, I've installed the sample app from Google (https://github.com/googlesamples/android-BluetoothLeGatt) to test if the devices are correctly y scanned, but tablets and smartphones are not detected (the bluetooth is visible and enabled in both cases).
In the list only appears bracelets like Xiaomi MiBand, Fitbit... and some Macbooks, but nothing else.
I've read this report: https://code.google.com/p/android/issues/detail?id=82293
and this post (with Android 6.0 must be enable the location): Bluetooth Low Energy startScan on Android 6.0 does not find devices
I've tested with multiple scan apps from the Play Store, but all of them show the same result... I'm going crazy.
Scanning from Settings -> Bluetooth the result is correct (smartphones and tablets are detected).
Any idea about this problem? Why this devices are not appearing on the BLE scan?
Smartphones and tablets used to test:
Samsung Galaxy S5
Xiaomi Redmi Note 2
BQ Edison 2
iPhone 5
If device has BLE it does not mean that it will be visible (broadcast) any data by default. In order to achieve communication between two smart phones you need to have (install or write your own) application that uses BLE to create proper BLE service that will be exposed to other devices.
Some BLE capable devices such is iPhone for example broadcasts BAS (Battery Service) or similar, but I don't think that Android does.
So, don't expect to find any device on scan that you have described, and if you still need
to communicate two smartphones with Android 5.x through BLE
try to read Bluetooth Low Energy documentation and be ready to understand UUID, GATT, Characteristic...
Would a Bluetooth LE Jedi know any trick how to get a reliable BLE scanning mode on cheap Android 4.4 devices ?
Everything works fine from Android 5 to 6, and most of the Android 4.4 phones...
However, on some cheap phones with 4.4 we encounter random issues, some phones do not detect anything, or sometimes just a few beacons among others, depending on environment, daytime, weather, or whatever... It's obviously due to a poor software or hardware on this side, but is there any trick to make it more stable programmatically ? (for example enabling / disabling Bluetooth regularly)
EDIT
To describe a typical behavior:
First, note that it is the exact same behavior with all scanning Apps I could test (Estimote, Kontakt.io, AltBeacon, etc. etc.) - so this is much probably not a matter of App implementation.
It occurs only below Android 5 (4.4.2, 4.4.3, 4.4.4) and on cheap devices, never on phones like a Samsung S5 for example.
The behavior: let's assume we have 5 beacons very close (less than 2 meters, all working fine).
- Once rebooted the phone finds 5 beacons for 1 or 2 minutes.
- Then it finds nothing for 5 minutes.
- After a refresh it finds 2 beacons.
- Another refresh of the scan: only 1 found. Then none... etc.
I could not find any logic, for now it looks erratic.
Enabling / disabling Wifi / Bluetooth, Bluetooth+Wifi, Wifi then Bluetooth, etc. make sometimes the scan find one more beacon, sometimes not... there is probably not much difference if I just wait without changing those params.
The only way to get back a reliable scan is to reboot the device... then it works only for 1 or 2 minutes again...
It occurs on some very different devices (a Wiko Sunset, a Samsung XCover, an Orange Roya).
On more recent devices (Nexus 6, Samsung S5, Samsung A4...), 100% of the beacons are detected, for hours, and never lost.
So, as the complete reboot is actually the best solution to get all beacons detected I was wondering if there is a way to "refresh" the device's Bluetooth module without rebooting it... Or if we just have to become a philosopher about this ;-)
if you are develop your application using node.js then there are many api's avaliable which may work for you.But in case of android it is totally depend on your android version
I'm currently trying to use a smartwatch LG G Watch R (fully updated) as a Beacon Scanner.
The Beacons are made by Estimote, so I'm using its SDK.
Using the smartphone I have no problem at all, but with the smartwatch I receive the signal from the beacons every 5 seconds despite having set both on the app and on the beacons the advertising time at 325ms.
The code is basically the same used on the smartphone.
Any ideas?
I don't know about the LG watch, but I realized similar behavior with other devices, like the Moto G2 for example. Even though the code is exactly the same, different devices handle it differently. It might be due to different chipsets used or how they are implemented.
Go to the logcat (without filtering the app) and look at the times when scans are started, stopped and when results are received. You might see that the scan process makes random "breaks" for no visible reason. Maybe it's the same issue with your watch.
Unfortunately I don't know about a solution.