Estimote / Android-Fleet-Management-SDK

Estimote Fleet Management SDK for Android
https://developer.estimote.com
MIT License
836 stars 451 forks source link

Cannot connect to beacon using Cordova #112

Closed anulman closed 9 years ago

anulman commented 9 years ago

TL;DR: If this issue sounds familiar, ensure you've bundled SDK 0.6.1+

beaconConnection.authenticate() times out when attempting to establish a BeaconConnection in a Cordova plugin.

I've tried to establish a connection to a beacon using the Estimote Android app, the Estiimote Android-SDK Demo app, and a Cordova-wrapped app using a fork of the Evothings plugin I've been extending.

The Cordova plugin implementation exclusively throws errors: there was a 503 once; otherwise it's been consistently timeouts.

Both the Estimote app and the Estimote Demo app are able to connect to beacons as expected, which seems to rule out private behaviour & shared antenna issues some Android devices reportedly experience.

I suspect there is an incompatible jar in play, though may also have missed Occam's Razor while debugging.

Should I keep hunting, or does this look internal?


Will share details, in case they're of use:

After printing and reviewing the stacktrace, I thought OkHTTP was the issue (spoiler: inconclusive). Turns out Cordova used to include a copy of OkHTTP its builds; this default was only recently removed.

I've since updated to Cordova v5.0.0, incl a recent cordova-android build (i.e. without embedded OkHTTP), and Android API level 22 / the latest SDK tools + build tools. Now, neither onAuthenticated nor onAuthenticationError methods are getting triggered after calling mBeaconConnection.authenticate() (also tested by replacing the constructor's beacon with beacon.getMacAddress().concat("foo")). Ranging continues to function.

I've also tried with & without pausing ranging / monitoring events (also w/ & w/o disconnecting the BeaconManager). Tried commenting this out in the Demo App's ListBeaconsActivity#onStop as well and it did not affect results, so was not expecting much :)

I hope this report doesn't come off negatively. I've enjoyed hacking with Estimotes for some time now, and appreciate how the SDK + APIs have evolved with the product. Sending a big :+1: to the team!

D/CordovaLog( 8270): file:///android_asset/www/assets/funnel-site-f6b66cab0a45bb30c0647c20066d3081.js: Line 1 : could not connect to beacon: com.estimote.sdk.exception.EstimoteDeviceException: timeout
D/CordovaLog( 8270):    at com.estimote.sdk.connection.BeaconConnection$1.failure(BeaconConnection.java:164)
D/CordovaLog( 8270):    at com.estimote.sdk.cloud.internal.InternalEstimoteCloud$4.failure(InternalEstimoteCloud.java:206)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.retrofit_v1_9_0.retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
D/CordovaLog( 8270):    at android.os.Handler.handleCallback(Handler.java:733)
D/CordovaLog( 8270):    at android.os.Handler.dispatchMessage(Handler.java:95)
D/CordovaLog( 8270):    at android.os.Looper.loop(Looper.java:157)
D/CordovaLog( 8270):    at android.app.ActivityThread.main(ActivityThread.java:5356)
D/CordovaLog( 8270):    at java.lang.reflect.Method.invokeNative(Native Method)
D/CordovaLog( 8270):    at java.lang.reflect.Method.invoke(Method.java:515)
D/CordovaLog( 8270):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
D/CordovaLog( 8270):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
D/CordovaLog( 8270):    at dalvik.system.NativeStart.main(Native Method)
D/CordovaLog( 8270): Caused by: com.estimote.sdk.exception.EstimoteServerException: timeout
D/CordovaLog( 8270):    ... 11 more
D/CordovaLog( 8270): Caused by: com.estimote.sdk.repackaged.retrofit_v1_9_0.retrofit.RetrofitError: timeout
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.retrofit_v1_9_0.retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:394)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.retrofit_v1_9_0.retrofit.RestAdapter$RestHandler.access$000(RestAdapter.java:219)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.retrofit_v1_9_0.retrofit.RestAdapter$RestHandler$1.obtainResponse(RestAdapter.java:277)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.retrofit_v1_9_0.retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
D/CordovaLog( 8270):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
D/CordovaLog( 8270):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.retrofit_v1_9_0.retrofit.Platform$Android$2$1.run(Platform.java:137)
D/CordovaLog( 8270):    at java.lang.Thread.run(Thread.java:841)
D/CordovaLog( 8270): Caused by: java.io.InterruptedIOException: timeout
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okio_v1_3_0.okio.AsyncTimeout.exit(AsyncTimeout.java:249)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okio_v1_3_0.okio.AsyncTimeout$2.read(AsyncTimeout.java:217)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okio_v1_3_0.okio.RealBufferedSource.indexOf(RealBufferedSource.java:295)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okio_v1_3_0.okio.RealBufferedSource.indexOf(RealBufferedSource.java:289)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okio_v1_3_0.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:196)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okhttp_v2_2_0.com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:187)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okhttp_v2_2_0.com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okhttp_v2_2_0.com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:791)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okhttp_v2_2_0.com.squareup.okhttp.internal.http.HttpEngine.access$200(HttpEngine.java:90)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okhttp_v2_2_0.com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:784)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okhttp_v2_2_0.com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:645)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okhttp_v2_2_0.com.squareup.okhttp.Call.getResponse(Call.java:263)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okhttp_v2_2_0.com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:219)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okhttp_v2_2_0.com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:192)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.okhttp_v2_2_0.com.squareup.okhttp.Call.execute(Call.java:79)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.retrofit_v1_9_0.retrofit.client.OkClient.execute(OkClient.java:53)
D/CordovaLog( 8270):    at com.estimote.sdk.repackaged.retrofit_v1_9_0.retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:325)
D/CordovaLog( 8270):    ... 7 more
anulman commented 9 years ago

Appreciate the prompt response Piotr. Strange that I only see it in email, not in this thread—the email even links here!

I actually upgraded the bundled SDK when init'ing the fork 4 days ago, extracting + renaming the jar from this repo's aar.

anulman commented 9 years ago

[just saw c5e847f62b7f451b6770ec888259b38d0af00a5c]

anulman commented 9 years ago

i can haz auth! :+1:

heypiotr commented 9 years ago

Great! :tada: :smiley:

(Can't see my reply too, not sure what happened.)