msupply-foundation / msupply-cold-chain

Android application for viewing and monitoring temperatures of fridges
GNU General Public License v3.0
3 stars 3 forks source link

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

Closed jmbrunskill closed 1 month ago

jmbrunskill commented 2 months ago

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 }
}