Bluetooth Operations
Cordova ==> Bluetooth module
Pair
To pair a peripheral, pass its ID
to the pair
method:
const peripheralID = 3; // choose a peripheral
// Get peripheral object and log pairing instructions
const peripheral = await ValidicMobile.InformBluetooth.getPeripheral(peripheralID);
log(peripheral.pairingInstructions);
try {
await ValidicMobile.InformBluetooth.pair(peripheral.id);
log("Pairing completed.");
}
catch (error) {
log("Pairing error: " + JSON.stringify(error));
}
Read
To read a peripheral, pass its ID
to the read
method:
const peripheralID = 3; // choose a peripheral
// Get peripheral object and log reading instructions
const peripheral = await ValidicMobile.InformBluetooth.getPeripheral(peripheralID);
log(peripheral.readingInstructions);
try {
await ValidicMobile.InformBluetooth.read(peripheral.id);
log("Reading completed.");
}
catch (error) {
log("Reading error: " + JSON.stringify(error));
}
Events
Events can be listened for by attaching a listener to the document:
document.addEventListener(ValidicMobile.InformBluetooth.InformBluetoothReadyToReadEvent, onBluetoothReadyToRead);
- InformBluetoothReadyToReadEvent: event fired when a Bluetooth device is ready to be read in the foreground.
- PassiveReadyToReadEvent: event fired when a Bluetooth device is readu to be read passively.
- PassiveDidReadEvent: event fired when a passive read completes. The event object will have an array of collected records in it.
- PassiveDidFailEvent: event fired when a passive read fails. The event object will have error details in it.
Updated 2 days ago