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

Update to Java 11, react-native-ble-plx 3.1.2 #299

Merged
merged 3 commits into from
May 17, 2024

Conversation

jmbrunskill
Copy link
Contributor

@jmbrunskill jmbrunskill commented Apr 29, 2024

This PR Updates the react-native-ble-plx library.

The updated library might help with data collection reliability issues such as #251 (Temperature Spikes)
It also paves the way for reading the advertisement packets as it provides access to the Raw scan data.

Inorder to get the new version working I had to use a newer version of Java and target a newer version of the Android SDK. This seems like a bit of a shame in some ways but also not a bad thing?

A POC of reading this has been done, example code here...


const rawBuffer = Buffer.from(device.rawScanRecord, 'base64')

interface ParsedData {
  battery?: number
  logIntevalSec?: number
  storedLogCount?: number
  currentTemp?: number
  currentHumidity?: number
}

const parseData = (rawScanRecord: Buffer) => {
  if (rawScanRecord.length < 16) {
    return null
  }
  const version = rawScanRecord.readUInt8(7)
  // console.log('version:', version)
  if (version !== 23) {
    // Unsupported version
    return null
  }

  const battery = rawScanRecord.readUInt8(8)

  const logIntevalSec = rawScanRecord.readUInt16BE(9)

  const storedLogCount = rawScanRecord.readUInt16BE(11)

  const currentTemp = rawScanRecord.readUInt16BE(13) / 10.0

  const currentHumidity = rawScanRecord.readUInt16BE(15) / 10.0

  return { battery, logIntevalSec, storedLogCount, currentTemp, currentHumidity }
}


```
export JDK_HOME=~/.jenv/versions/oracle64-1.8.0.192 && JAVA_HOME=~/.jenv/versions/oracle64-1.8.0.192 && yarn start
sdk use java 11.0.23-zulu
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this as it seems we need java11+ now that we're targeting a SDK 23.
Haven't tired 17 or other more modern ones, wasn't working before...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api level 23 is android 6 - given that the samsung I'm using is older, and android 12.. we're probably ok

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Android >= 12 -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
Copy link
Contributor Author

@jmbrunskill jmbrunskill Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what we're using now if I understand correctly...

PendingIntent contentIntent = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
contentIntent = PendingIntent.getActivity
(context, 0, notificationIntent, PendingIntent.FLAG_MUTABLE);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparenlty IMMUTABLE Is safer but wanted to just get it working for now...

@mark-prins mark-prins self-assigned this Apr 29, 2024
Copy link
Contributor

@mark-prins mark-prins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

App is running nicely - so I approve that part. Am wondering though if an older version of the ble-service is being used? can you check / revert those changes? shouldn't affect the upgrade aspec.

.yalc/msupply-ble-service/package.json Outdated Show resolved Hide resolved
.yalc/msupply-ble-service/src/Bluetooth/BleService.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@mark-prins mark-prins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jmbrunskill - Looks good!

@jmbrunskill jmbrunskill merged commit dc36e14 into master May 17, 2024
@jmbrunskill jmbrunskill deleted the 251-update-bluetooth-library branch May 17, 2024 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants