Convenience functions for Web Bluetooth
npm install --save web-bluetooth-utils
navigator.bluetooth.requestDevice({ filters: [{ services: ['battery_service'] }] })
.then(device => device.readUint8CharacteristicValueFromPrimaryService('battery_service', 'battery_level', 0 /* offset */))
.then(value => {
console.log('Battery percentage is ' + value));
});
BluetoothRemoteGATTCharacteristic.getFloat32Value(byteOffset, littleEndian = true)
Returns the cached value of the characteristic as a signed 32-bit float (float) at the specified byte offset.
BluetoothRemoteGATTCharacteristic.getFloat64Value(byteOffset, littleEndian = true)
Returns the cached value of the characteristic as a signed 64-bit float (double) at the specified byte offset.
BluetoothRemoteGATTCharacteristic.getInt16Value(byteOffset, littleEndian = true)
Returns the cached value of the characteristic as a signed 16-bit integer (short) at the specified byte offset.
BluetoothRemoteGATTCharacteristic.getInt32Value(byteOffset, littleEndian = true)
Returns the cached value of the characteristic as a signed 32-bit integer (long) at the specified byte offset.
BluetoothRemoteGATTCharacteristic.getInt8Value(byteOffset)
Returns the cached value of the characteristic as a signed 8-bit integer (byte) at the specified byte offset.
BluetoothRemoteGATTCharacteristic.getStringValue(encoding = 'utf8')
Returns the cached value of the characteristic as a string containing the text decoded with the decoding algorithm.
BluetoothRemoteGATTCharacteristic.getUint16Value(byteOffset, littleEndian = true)
Returns the cached value of the characteristic as an unsigned 16-bit integer (unsigned short) at the specified byte offset.
BluetoothRemoteGATTCharacteristic.getUint32Value(byteOffset, littleEndian = true)
Returns the cached value of the characteristic as an unsigned 32-bit integer (unsigned long) at the specified byte offset.
BluetoothRemoteGATTCharacteristic.getUint8Value(byteOffset)
Returns the cached value of the characteristic as an unsigned 8-bit integer (unsigned byte) at the specified byte offset.
BluetoothRemoteGATTService.getCharacteristics(characteristics)
If characteristics
is an Array, returns all service's characteristics matching all characteristics UUIDs.
If characteristics
is a String, returns all service's characteristics matching the unique UUID.
BluetoothDevice.getCharacteristicFromPrimaryService(serviceUuid, characteristicUuid)
Returns the characteristic from a primary service.
BluetoothDevice.readCharacteristicValueFromPrimaryService(serviceUuid, characteristicUuid, optionalCallback, optionalArgs)
Reads the value of a characteristic from a primary service as a DataView
object.
If optionalCallback
is passed, it will be called with the characteristic value and optionalArgs
arguments.
BluetoothDevice.readFloat32CharacteristicValueFromPrimaryService(serviceUuid, characteristicUuid, byteOffset, littleEndian = true)
Reads the value of the characteristic from a primary service as a signed 32-bit float (float) at the specified byte offset.
BluetoothDevice.readFloat64CharacteristicValueFromPrimaryService(serviceUuid, characteristicUuid, byteOffset, littleEndian = true)
Reads the value of the characteristic from a primary service as a signed 64-bit float (double) at the specified byte offset.
BluetoothDevice.readInt16CharacteristicValueFromPrimaryService
Reads the value of the characteristic from a primary service as a signed 16-bit integer (short) at the specified byte offset.
BluetoothDevice.readInt32CharacteristicValueFromPrimaryService(serviceUuid, characteristicUuid, byteOffset, littleEndian = true)
Reads the value of the characteristic from a primary service as a signed 32-bit integer (long) at the specified byte offset.
BluetoothDevice.readInt8CharacteristicValueFromPrimaryService(serviceUuid, characteristicUuid, byteOffset)
Reads the value of the characteristic from a primary service as a signed 8-bit integer (byte) at the specified byte offset.
BluetoothDevice.readStringCharacteristicValueFromPrimaryService(serviceUuid, characteristicUuid, byteOffset)
Reads the value of the characteristic from a primary service as a string containing the text decoded with the decoding algorithm.
BluetoothDevice.readUint16CharacteristicValueFromPrimaryService(serviceUuid, characteristicUuid, byteOffset, littleEndian = true)
Reads the value of the characteristic from a primary service as an unsigned 16-bit integer (unsigned short) at the specified byte offset.
BluetoothDevice.readUint32CharacteristicValueFromPrimaryService(serviceUuid, characteristicUuid, byteOffset, littleEndian = true)
Reads the value of the characteristic from a primary service as an unsigned 32-bit integer (unsigned long) at the specified byte offset.
BluetoothDevice.readUint8CharacteristicValueFromPrimaryService(serviceUuid, characteristicUuid, byteOffset)
Reads the value of the characteristic from a primary service as an unsigned 8-bit integer (unsigned byte) at the specified byte offset.
BluetoothDevice.writeCharacteristicValueFromPrimaryService(serviceUuid, characteristicUuid, data)
Writes data to a characteristic from a primary service.
BluetoothDevice.startCharacteristicNotificationsFromPrimaryService(serviceUuid, characteristicUuid, listener)
Start notifications from a characteristic from a primary service and attach an event listener.
BluetoothDevice.stopCharacteristicNotificationsFromPrimaryService(serviceUuid, characteristicUuid, listener)
Stop notifications from a characteristic from a primary service and remove an event listener.