web-bluetooth-vuex
A vuex module to interface with BLE devices through the Web Bluetooth API available in Chrome. For Linux and Macos Chrome support was available in 54, for windows 10 in version 70.
Installation
$ yarn add web-bluetooth-vuex# OR$ npm install web-bluetooth-vuex
Configuration
//Set up Vue & Vuex Vue //Create your vuex storelet store = state: {} modules: webBluetooth: WebBluetoothModule
Use inside a .vue
Available Actions
addDevice
Add devices in the proxmity to the store. Accepts a couple of different combinations. The snipplet below illustrates the combinations. The services array can take the form of names of established services, 16bit uuid and 128bit uuids.
// Scan for any devices around you, services determines which possible services// you can acccess when connectedconst option1 = anyDevices: true services:'device_information' // Scan for a device with specific name around you, services determines which// possible services you can acccess when connectedconst option2 = name: 'Demo Device' services'device_information' // Scan for a devices with a name prefix round you, services determines which// possible services you can acccess when connectedconst option3 = namePrefix: 'Demo Device' services'device_information' // Scan for a devices with a specific set of services advertisedconst option4 = services'device_information' store
removeDevice
Disconnects from device and then removes device and all its services & characteristics from the store.
let options = device: deviceReferenceFromStorestore
connectDevice
Connects to a device that has been added to the store.
let options = device: deviceReferenceFromStorestore
disconnectDevice
Connects to a device that has been added to the store.
let options = device: deviceReferenceFromStorestore
discoverServices
For a connected devices performs a service and characteristics discovery. characteristics will also be configuerd according to their permissions. Read, Write, Notify, Indicate permissions will be setup with apppripate callbacks and the store will update with value changes.
// Discover all services specifed in addDevicelet option1 = device: deviceReferenceFromStore // Discover a specific service specifed in addDevice// in this incase the uuid of the Battery Servicelet option2 = device: deviceReferenceFromStore uuid: BluetoothUUID store
writeCharacteristic
Write an arraybuffer to the characteristic
let valueToWrite = Uint8Arraylet option2 = characteristic: characteristicReferenceFromStore value: valueToWrite store
Available Getters
device(deviceId)
const device = storegetters'webBluetooth/device'deviceId
servicesForDevice(deviceId)
const services = storegetters'webBluetooth/servicesForDevice'deviceId
serviceForDevice(deviceId,uuid)
const service = storegetters'webBluetooth/serviceForDevice'deviceIdBluetoothUUID
characteristicsForService(service)
const characteristics = storegetters'webBluetooth/characteristicsForService'serviceFromStore
characteristicForService(service,uuid)
const characteristic = storegetters'webBluetooth/characteristicForService'serviceFromStore BluetoothUUID
Available state
devices
const devices = storestatewebBluetoothdevices
services
const services = storestatewebBluetoothservices
characteristics
const characteristics = storestatewebBluetoothcharacteristics