Bluetooth Operations

React Native ==> Bluetooth module

Pair

Some BluetoothPeripheral profiles require pairing with the device before measurements can be retrieved from the device. These BluetoothPeripherals will have RequiresPairing == true and will have PairingInstruction that can be used to display to the end user

try{
  const peripheral = await ValidicBluetooth.getPeripheral(2); // A&D BP cuff
  // do something with peripheral.pairingInstructions
  console.log(peripheral.pairingInstructions);
  // then pair
  const result = await ValidicBluetooth.pair(peripheral.id)
} catch (e) {
  console.log(e)
}

Read

To take a reading from a BluetoothPeripheral device call readPeripheral

try{
  const readResult = await ValidicBluetooth.readPeripheral(2)
} catch (e) {
  console.log(e)
}

By default, measurements that are collected are automatically submitted to the Validic API. To prevent autosubmitting the readings and submitting them to the server, use the autoSubmit option and use ValidicCore to submit the records collected.

try{
  const result = await ValidicBluetooth.readPeripheral(2, {"autoSubmit": false})
  result.measurements.forEach(measurement=>{
    await ValidicInfomCore.submit(measurement)
  }
} catch (e) {
  console.log(e)
}

Canceling an operation

To cancel an inflight Promise after calling ValidicBluetooth.pairPeripheral or ValidicBluetooth.readPeripheral call the ValidicBluetooth.cancelOperation function. If an operation is currently in place, then the Promise returned will call its reject function with a cancellation method.

ValidicBluetooth.readPeripheral(1, {autoSubmit: true})
.then(()=>{
  console.log("Paired with Peripheral");
})
.catch(e=>{
  console.log(e);
});

// ...
ValidicBluetooth.cancelOperation();


Custom global error handler

For more details on handling errors, refer to the Native Android Inform SDK documentation on Custom Global Error Handler.


Special considerations

Most supported Bluetooth devices function similarly and you can follow the instructions in Bluetooth permissions, Bluetooth Operations and Passive Read to work with them.

However, a few of our supported devices have additional requirements and/or considerations that you need to be aware of. Those are covered in the Native Android Inform SDK Bluetooth Behavior documentation.