Driversnote-Dev / react-native-kontaktio

React Native (iOS and Android) library for Kontakt.io beacons (and all other beacons)
MIT License
112 stars 48 forks source link

Beacon detected but uniqueID and Battery level is null (old or new chips of Kontakt beacons) #116

Closed hl2000 closed 1 year ago

hl2000 commented 1 year ago

Hi guys,

I am experiencing a strange issue with an Android device. the device is Samsung Galaxy A52s 5G running Android 13 and Samsung s21 running Android 13. Beacon is a Kontakt beacon.

The beacon has been detected, but the value for uniqueID and Battery are null, please see the screenshot below. the major, minor, uuid are all correctly detected.

git-hub-beacon-issue

I created a simple app to verify this issue, I followed the readme file. Start a new React Native TypeScript project (npx react-native init BeaconTest --template react-native-template-typescript)

then I replace the content of App.tsx with the Android example code below. https://github.com/Driversnote-Dev/react-native-kontaktio/blob/master/Example/src/Example.android.tsx

I have also added permission checks for ACCESS_FINE_LOCATION, BLUETOOTH_SCAN, BLUETOOTH_CONNECT

Here is the permission section of my manifest file. (I am trying to find the issue seems particularly for Android 13, not 100% sure if other Android versions also have this issue)

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />

<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

part of the android\build.gradle

ext {
    buildToolsVersion = "31.0.0"
    minSdkVersion = 21
    compileSdkVersion = 31
    targetSdkVersion = 31

    if (System.properties['os.arch'] == "aarch64") {
        // For M1 Users we need to use the NDK 24 which added support for aarch64
        ndkVersion = "24.0.8215888"
    } else {
        // Otherwise we default to the side-by-side NDK version from AGP.
        ndkVersion = "21.4.7075529"
    }
}

I added a line to display the detected beacon objects on the screen: stringify: {JSON.stringify(beacon)}

from the screenshot, you can see the value for uniqueID and Battery are null.

What do you think guys? What could be wrong? Any permission not granted to allow the library to acquire the Kontakt exclusive values? or the Kontakt library needs an update? in this file android/app/build.gradle I tried to change the implementation "io.kontakt.mvn:sdk:7.0.6" to be implementation "io.kontakt.mvn:sdk:7.0.12.2", seems no different.

Has anyone seen a similar issue before, please help! or please point me to a possible direction to dig more...

Thanks!

hl2000 commented 1 year ago

ok, finally, I found the reason and the solution.

For Android, Kontakt uses different methods for new and old chips.

For beacons made with nrf 51 the old chip, the beacon event listener(e.g. beaconDidAppear) is still working and able to get the uniqueId and battery level, but for beacons made with new nrf 52 chip, you will have to listen to the profile related events(e.g. profileDidAppear) to get the uniqueId and battery level.

For iOS, you can still use the discovery events(e.g. didDiscoverDevices) to get the uniqueId and battery level for both old and new chips.

This null uniqueId issue has been mentioned before: https://github.com/Driversnote-Dev/react-native-kontaktio/issues/76 When I have old beacons with old chips(ordered in 2019), the beaconDidAppearcan already gives me the uniqueId.

Later I got the new Kontakt beacons, beaconDidAppearcan return empty(null) uniqueId, then I found this https://github.com/kontaktio/kontakt-android-sdk/issues/193 I realised the uniqueId issue mentioned above is actually related to "new beacons", so have to use the profile related event to get.

If anyone else has similar issues, happy to discuss.