npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

web-bluetooth-utils

v1.1.1

Published

Convenience functions for Web Bluetooth

Downloads

15

Readme

web-bluetooth-utils

Convenience functions for Web Bluetooth

Install

npm install --save web-bluetooth-utils

Example usage

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

API

Characteristic.getFloat32Value

BluetoothRemoteGATTCharacteristic.getFloat32Value(byteOffset, littleEndian = true)

Returns the cached value of the characteristic as a signed 32-bit float (float) at the specified byte offset.

Characteristic.getFloat64Value

BluetoothRemoteGATTCharacteristic.getFloat64Value(byteOffset, littleEndian = true)

Returns the cached value of the characteristic as a signed 64-bit float (double) at the specified byte offset.

Characteristic.getInt16Value

BluetoothRemoteGATTCharacteristic.getInt16Value(byteOffset, littleEndian = true)

Returns the cached value of the characteristic as a signed 16-bit integer (short) at the specified byte offset.

Characteristic.getInt32Value

BluetoothRemoteGATTCharacteristic.getInt32Value(byteOffset, littleEndian = true)

Returns the cached value of the characteristic as a signed 32-bit integer (long) at the specified byte offset.

Characteristic.getInt8Value

BluetoothRemoteGATTCharacteristic.getInt8Value(byteOffset)

Returns the cached value of the characteristic as a signed 8-bit integer (byte) at the specified byte offset.

Characteristic.getStringValue

BluetoothRemoteGATTCharacteristic.getStringValue(encoding = 'utf8')

Returns the cached value of the characteristic as a string containing the text decoded with the decoding algorithm.

Characteristic.getUint16Value

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.

Characteristic.getUint32Value

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.

Characteristic.getUint8Value

BluetoothRemoteGATTCharacteristic.getUint8Value(byteOffset)

Returns the cached value of the characteristic as an unsigned 8-bit integer (unsigned byte) at the specified byte offset.

Service.getCharacteristics

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.

Device.getCharacteristicFromPrimaryService

BluetoothDevice.getCharacteristicFromPrimaryService(serviceUuid, characteristicUuid)

Returns the characteristic from a primary service.

Device.readCharacteristicValueFromPrimaryService

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.

Device.readFloat32CharacteristicValueFromPrimaryService

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.

Device.readFloat64CharacteristicValueFromPrimaryService

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.

Device.readInt16CharacteristicValueFromPrimaryService

BluetoothDevice.readInt16CharacteristicValueFromPrimaryService

Reads the value of the characteristic from a primary service as a signed 16-bit integer (short) at the specified byte offset.

Device.readInt32CharacteristicValueFromPrimaryService

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.

Device.readInt8CharacteristicValueFromPrimaryService

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.

Device.readStringCharacteristicValueFromPrimaryService

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.

Device.readUint16CharacteristicValueFromPrimaryService

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.

Device.readUint32CharacteristicValueFromPrimaryService

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.

Device.readUint8CharacteristicValueFromPrimaryService

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.

Device.writeCharacteristicValueFromPrimaryService

BluetoothDevice.writeCharacteristicValueFromPrimaryService(serviceUuid, characteristicUuid, data)

Writes data to a characteristic from a primary service.

Device.startCharacteristicNotificationsFromPrimaryService

BluetoothDevice.startCharacteristicNotificationsFromPrimaryService(serviceUuid, characteristicUuid, listener)

Start notifications from a characteristic from a primary service and attach an event listener.

Device.stopCharacteristicNotificationsFromPrimaryService

BluetoothDevice.stopCharacteristicNotificationsFromPrimaryService(serviceUuid, characteristicUuid, listener)

Stop notifications from a characteristic from a primary service and remove an event listener.