Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth Low Energy scan failed with error code: -99 #19

Closed
5 tasks done
trietlam opened this issue Feb 1, 2018 · 5 comments
Closed
5 tasks done

Bluetooth Low Energy scan failed with error code: -99 #19

trietlam opened this issue Feb 1, 2018 · 5 comments
Assignees

Comments

@trietlam
Copy link

trietlam commented Feb 1, 2018

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • My beacons have Estimote Monitoring enabled (Check it in the Estimote Cloud, or via app)
    • My Android device/devices supports BLE and has Android OS version >= 5.0.0
    • My Android device/devices have bluetooth enabled
    • My app has Location Permissions granted

Basic information

Estimote SDK version: [Paste here the SDK version that you are using (like 0.1.0-alpha.6)]
com.estimote:proximity-sdk:0.2.0

Android devices affected: [Paste here your Android device model/models that you are having problems with.]
Samsung Galaxy Tab A6

Android OS version affected: [Android OS version (ex. Oreo 8.0.0)]

  • Android version 5.1.1
    Android security patch level: 1 Sept 2016

  • [Updated] I also got similar error on Samsung Galaxy S4 (Android 5.0.1)

Beacon hardware version: [Paste here your beacons hardware version (you can check that in Estimote Cloud).]
G1.12

Description

App crash with fatal exception when using estimote-proximity android sdk.
Same code works on Samsung Galaxy Tab A with Android version 5.1.1 security patch level 2015-12-01

Expected behavior: [What you expect to happen]
Should receive callback for withOnPacketFoundAction

Actual behavior: [What actually happens]
App crash with Fatal exception

Additional information

Here my code snippet

    if(SystemRequirementsChecker.checkWithDefaultDialogs(getCurrentActivity())) {
      scanner = new EstimoteBluetoothScannerFactory(reactContext).getSimpleScanner();
      scanHandler = scanner.estimoteTelemetryFrameBScan()
              .withLowLatencyPowerMode()
              .withOnPacketFoundAction(new Function1<EstimoteTelemetryFrameB, Unit>() {
                @Override
                public Unit invoke(EstimoteTelemetryFrameB tlm) {
                  Log.i("Estimote", "Estimote telemetry id: " + tlm.getShortId() + ", temp: " + tlm.getTemperatureInCelsiusDegrees());

                  return null;
                }
              })
              .withOnScanErrorAction(new Function1<Throwable, Unit>() {
                @Override
                public Unit invoke(Throwable throwable) {
                  Log.e("Estimote", "onScanError", throwable);
                  hasError = true;
                  return null;
                }
              })
              .withTimeout(60, TimeUnit.SECONDS)
              .start();
    }

And here is stack trace

02-01 13:35:06.515 4690-4690/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 Process: com.estimotetrackback, PID: 4690
                                                 io.reactivex.exceptions.UndeliverableException: java.lang.Exception: Bluetooth Low Energy scan failed with error code: -99
                                                     at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:349)
                                                     at io.reactivex.internal.operators.observable.ObservableCreate$CreateEmitter.onError(ObservableCreate.java:74)
                                                     at com.estimote.scanning_sdk.packet_provider.scanner.PostLollipopEstimoteScanner$scan$1$callback$1.onScanFailed(PostLollipopEstimoteScanner.kt:27)
                                                     at android.bluetooth.le.BluetoothLeScanner$1.run(BluetoothLeScanner.java:442)
                                                     at android.os.Handler.handleCallback(Handler.java:739)
                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                     at android.os.Looper.loop(Looper.java:145)
                                                     at android.app.ActivityThread.main(ActivityThread.java:6939)
                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                     at java.lang.reflect.Method.invoke(Method.java:372)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
                                                  Caused by: java.lang.Exception: Bluetooth Low Energy scan failed with error code: -99
                                                     at com.estimote.scanning_sdk.packet_provider.scanner.PostLollipopEstimoteScanner$scan$1$callback$1.onScanFailed(PostLollipopEstimoteScanner.kt:27) 
                                                     at android.bluetooth.le.BluetoothLeScanner$1.run(BluetoothLeScanner.java:442) 
                                                     at android.os.Handler.handleCallback(Handler.java:739) 
                                                     at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                     at android.os.Looper.loop(Looper.java:145) 
                                                     at android.app.ActivityThread.main(ActivityThread.java:6939) 
                                                     at java.lang.reflect.Method.invoke(Native Method) 
                                                     at java.lang.reflect.Method.invoke(Method.java:372) 
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

Not sure I'm doing anything wrong because I could not find example in Java.
Any help would be appreciated :)

@pawelDylag
Copy link
Contributor

Hello @trietlam

Thank you for reporting this issue and all the necessary information provided.
The Bluetooth Low Energy scan failed with error code: -99 is thrown when there are too many scanning filters applied. Each .start() method applies at least one filter. Some Samsung devices are unable to handle more than 12 of them, so I guess that your scan gets started that many times without being stopped. My questions to you:

  1. Is the crash occurring on the very first run of your app, or after some time?
  2. Are you starting the scan in some kind of a loop?
  3. I can see you are using .withTimeout(60, TimeUnit.SECONDS) - are you starting it again after this time has passed?
  4. Are you calling .stop() on your scanHandler ?

Regards,
Paweł

@pawelDylag pawelDylag self-assigned this Feb 2, 2018
@trietlam
Copy link
Author

trietlam commented Feb 6, 2018

Hello @pawelDylag

I've uploaded the project to https://github.com/trietlam/estimote-proximity-sample, hope it helps for your investigation.

Regarding your questions:
0. Is the crash occurring on the very first run of your app, or after some time?
--> It's occurring on the very first run

  1. Are you starting the scan in some kind of a loop?
    --> No

  2. I can see you are using .withTimeout(60, TimeUnit.SECONDS) - are you starting it again after this time has passed?
    --> I intended to try this, but it crashes right at first call

  3. Are you calling .stop() on your scanHandler ?
    --> No

Cheers!

@pawelDylag
Copy link
Contributor

pawelDylag commented Feb 7, 2018

Hey @trietlam

Thanks for the sample. I think we need to add support for phones/tablets not supporting hardware filtering. I will add a task to fix it to our backlog. You can test your app on a different device if possible. Also, I would suggest calling scanHandler.stop() in your activity's onPause() method.

I'll keep you updated
Paweł

@pawelDylag
Copy link
Contributor

pawelDylag commented Feb 26, 2018

Hey @trietlam

We've added support for phones not supporting offloaded hardware filtering (scan filters) in SDK version 0.3.2.
The problem with your case is that on some phones (especially Samsung devices) there is a support for limited amount of HW filters (isOffloadedFilteringSupported() == true), but there is no way to know the max number apriori. This is causing -99 error, because our SDK "thinks" it's allowed to use as many scan filters as it needs, but sometimes exceeds the limit on some phones, resulting in the mentioned error.

We will think how to tackle this problem in a proper way (without ugly hacks like restarting the scanning under the hood) and will try to introduce them in the next releases.

For now, you can try 0.3.2 and check, if your Samsung device works with current changes.

Also, note that we've changed the path of BluetoothScanner - from scanning_sdk to scanning_plugin. You might need to fix your imports :)

Regards,
Paweł

@trietlam
Copy link
Author

trietlam commented Mar 5, 2018

Thanks @pawelDylag ,

It works now on my Galasxy S4 after I update to 0.3.2 and replace com.estimote.scanning_sdk.api.EstimoteBluetoothScannerFactory with com.estimote.scanning_plugin.api.EstimoteBluetoothScannerFactory

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants