mmazzarolo/react-native-beacons-android

Any luck with Eddystone?

sudharsan1988 opened this issue ยท 23 comments

Hi, just wanted to check back to see whether you got a chance to look into the Eddystone support for this module. Man, this library is awesome :) If we could add Eddystone & Background service, that would cover most of the things.

Hello there!
Unfortunately I can't test Eddystone support myself, I only have a bunch of Estimotes and Kontakt beacons for testing purpose.
I can help you debug their monitoring though! It's really not that hard, and no Java knowledge is needed.
First of all let's check if the default log I included can be helpful.
Start you application and in the terminal type: adb logcat | grep 'BeaconsAndroid' (you might also need to use the adb-reverse command because you're working on a real device).
Then start ranging for Eddystone beacons and tell me if you see anything logged in the console.

#8 is related

Regarding the background service... the last time I took a look at it it didn't seem doable on React-Native... but I would be happy to be proved wrong.

Hi, I really appreciate your prompt response. I just followed your instruction and here is some of the log content,

  1. I started Ranging with Estimote on Android device (Primary Packet Type - Eddystone URL/UID - I tried both)

  2. Here is code that I am using in my JS component file,

    `Beacons.detectCustomBeaconLayout('s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19');
    Beacons.detectCustomBeaconLayout('s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19;d:20-21');
    Beacons.detectCustomBeaconLayout('x,s:0-1=feaa,m:2-2=20,d:3-3,d:4-5,d:6-7,d:8-11,d:12-15');
    Beacons.detectCustomBeaconLayout('s:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-20v');

    Beacons.startRangingBeaconsInRegion('REGION1')
    .then(() => console.log(Beacons ranging started succesfully!))
    .catch(error => console.log(Beacons ranging not started, error: ${error}))

    DeviceEventEmitter.addListener('beaconsDidRange', (data) => {
    console.log('Found beacons!', data.beacons)
    })`

  3. Once installed on the device, I ran this command adb logcat | grep 'BeaconsAndroid'

  4. Below is the log content that I have got,

D/BeaconsAndroidModule( 6382): BeaconsAndroidModule - started
D/BeaconsAndroidModule( 6382): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 6382): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
E/AndroidRuntime( 6382): at com.mmazzarolo.beaconsandroid.BeaconsAndroidModule.sendEvent(BeaconsAndroidModule.java:105)
E/AndroidRuntime( 6382): at com.mmazzarolo.beaconsandroid.BeaconsAndroidModule.access$200(BeaconsAndroidModule.java:41)
E/AndroidRuntime( 6382): at com.mmazzarolo.beaconsandroid.BeaconsAndroidModule$2$1.didRangeBeaconsInRegion(BeaconsAndroidModule.java:233)
D/BeaconsAndroidModule( 8023): BeaconsAndroidModule - started
D/BeaconsAndroidModule( 8023): BeaconsAndroidModule - started
D/BeaconsAndroidModule( 8023): addParser - parser: s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19
D/BeaconsAndroidModule( 8023): addParser - parser: s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19;d:20-21
D/BeaconsAndroidModule( 8023): addParser - parser: x,s:0-1=feaa,m:2-2=20,d:3-3,d:4-5,d:6-7,d:8-11,d:12-15
D/BeaconsAndroidModule( 8023): addParser - parser: s:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-20v
D/BeaconsAndroidModule( 8023): startRanging, rangingRegionId: REGION1, rangingBeaconUuid: null
D/BeaconsAndroidModule( 8023): startRanging, success
D/BeaconsAndroidModule( 8023): rangingConsumer, called startRangingBeaconsInRegion()
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 8023): rangingConsumer didRangeBeaconsInRegion, beacons: []

It's always null. But not sure why isn't working for EddyStone. I switched the Primary Packet Type to default(iBeacon) in my Estimote and it's working awesome. Here is the log cat content for iBeacon

D/BeaconsAndroidModule( 9029): BeaconsAndroidModule - started
D/BeaconsAndroidModule( 9029): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 9029): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
E/AndroidRuntime( 9029): at com.mmazzarolo.beaconsandroid.BeaconsAndroidModule.sendEvent(BeaconsAndroidModule.java:105)
E/AndroidRuntime( 9029): at com.mmazzarolo.beaconsandroid.BeaconsAndroidModule.access$200(BeaconsAndroidModule.java:41)
E/AndroidRuntime( 9029): at com.mmazzarolo.beaconsandroid.BeaconsAndroidModule$2$1.didRangeBeaconsInRegion(BeaconsAndroidModule.java:233)
D/BeaconsAndroidModule( 9589): BeaconsAndroidModule - started
D/BeaconsAndroidModule( 9589): addParser - parser: m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24
D/BeaconsAndroidModule( 9589): startRanging, rangingRegionId: REGION1, rangingBeaconUuid: null
D/BeaconsAndroidModule( 9589): startRanging, success
D/BeaconsAndroidModule( 9589): rangingConsumer, called startRangingBeaconsInRegion()
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, beacons: [id1: b9407f30-f5f8-466e-aff9-25556b57fe6d id2: 19295 id3: 60697]
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, beacons: [id1: b9407f30-f5f8-466e-aff9-25556b57fe6d id2: 19295 id3: 60697]
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, beacons: [id1: b9407f30-f5f8-466e-aff9-25556b57fe6d id2: 19295 id3: 60697]
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, beacons: []
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, region: id1: null id2: null id3: null
D/BeaconsAndroidModule( 9589): rangingConsumer didRangeBeaconsInRegion, beacons: []

Thanks again for helping me out.

For the background service, I went through some forums and it seems, we can do it on React Native. Here is the stackoverflow link where people discussing on Background intent service,

http://stackoverflow.com/questions/34687473/background-service-on-react-native-android

Also, the below listed repo have this background service but it's been commented now. @devfd mentioned that he would release the new one with background service that even work when the android app is killed from app switcher.

Here is the link to his repo, https://github.com/devfd/react-native-workers

Here is the background service related files that are commented by author for now,

https://github.com/devfd/react-native-workers/blob/master/android/src/main/java/co/apptailor/Worker/JSService.java

https://github.com/devfd/react-native-workers/blob/master/android/src/main/java/co/apptailor/Worker/WorkerModule.java (find the startService() function.

Also, from the below article, it seems it's possible to use existing android native module, https://shift.infinite.red/shopping-external-libs-in-react-native-cfbc0c6e25cf#.fnrz9qh57

In that case, if we could integrate this, that would solve the back ground problem.

https://android-arsenal.com/details/1/4179

Of course, I could be wrong but I thought of sharing what I came up with in my findings. I also have to be honest with you that I never tried JAVA before.

Thank you so much @sudharsan1988, you've been incredibly helpful!

Regarding the Eddystone: you did everything right (you followed this, am I right?), but it still seems that the AltBeacons Library (the one I implemented in this module) is not able to detect the Eddystone beacons... that's weird and unfortunately without an Eddystone beacon it's not easy for me debugging this issue.
I'm sorry man, the only thing I can do is keeping this issue open hoping for the help of someone with a bit of Java knowledge and an Eddystone beacon to test.

Regarding the background service: thanks again, it seems doable now ๐Ÿ‘ , the only thing I need to investigate further is understanding if I can keep the service in the background even when the app is not in memory (aka when you swipe it from the recent apps). If it was a standard Android app it would be easy, but I don't know if being tied to JS can be a problem...

@mmazzarolo , really thanks for updating the readme. I'm sorry that I couldn't help you with Java part but whenever you need, I can do testing with the Eddystone(Estimote) that I have got.

Also, for the background service, could you take a look at this library as it's using the background service even when the app is killed. I have tested this myself and that works fine. I can get the push notifications even after I killed the app from the app switcher.

https://github.com/zo0r/react-native-push-notification

I'm sure, it can help us to understand how to integrate the Background service. I'm also trying to find out if there is any open source background service library is already out there for us to use. I will keep you posted.

Hi, this article may be helpful for background service. https://dzone.com/articles/how-to-develop-a-simple-step-counter-app-on-reactn

I tried their example app on Android Emulator but no luck. There are some issues in the Example app.

Here is their github repo, https://github.com/Singree/react-native-example-app

I'll take a look on this.

@sudharsan1988 sorry, I'm having two busy week at work, I'll take a look at all the links you posted as soon as you can.
@levint That's awesome :) hope to hear news soon, ping me if you need anything

Thank you guys!

@mmazzarolo , no worries! I will keep digging for the background service and keep you posted :)

@levint , thank you for helping us out. I have a Eddystone beacon(Estimote) with me. I can help you with any testing you want.

@mmazzarolo I have an Estimote beacon but with a firmware update now supports Eddystone!

It's not yet working on mine, as of this moment. I also tried installing Beacon Toy on my mobile phone and set it to broadcast as Eddystone-URL, but it still cannot be detected by the react-native app.

Edit:
The native BluetoothLeScanner is able to scan, however when it reaches the library's BeaconParser, it prints out: "This is not a matching Beacon advertisement."

https://github.com/AltBeacon/android-beacon-library/blob/2.9.1/src/main/java/org/altbeacon/beacon/BeaconParser.java

@levint thank you for your support.
It seems an altBeacon issue... if you still have some spare time you might try updating the altBeacon library (in the build.gradle).
I had a similiar issue in the past that was fixed just by downgrading the lib. ๐Ÿ‘

@mmazzarolo

UPDATE: I made it to work using an Eddystone-capable Beacon. I'll post my findings later. I made adjustments in both the Javascript and Native code. Using Alt Beacon 2.9

Hi @mmazzarolo, do you want me to submit a PR or would you like to do it on your own as per my findings?

Technically, adding a BeaconParser should be done before the Consumer (in the library's case, the ReactContextBaseJavaModule subclass) is binded to the BeaconManager instance via (mBeaconManager.bind(this)).

My proposed solution would be to check if the consumer is already bound to the manager instance before ranging and/or monitoring is done, probably on the start of startRanging/startMonitoring methods. If not yet bound, then we should bind it. (Instead of doing it in the constructor).

It is also possible to do it on the react-native side :)

@levint that's awesome!
Unfortunately I have two really busy weeks ahead, so PRs are welcome!
Otherwise I'll have to take a look at it next month :(

Thank you again!

@mmazzarolo Okay, will do before this week ends :)

@levint , awesome news! Is it possible for you to share your forked version of repo, I am very excited to test it :)

@levint, just curious to know whether you have got any chance to PR the changes regarding the Eddystone?

Hey @levint, sorry to bother you... do you have any info regarding Eddystone? Thanks!

@levint can u send ur PR regarding eddystone

Thanks

Hi,
May I ask if the library could support Eddystone now ?