@blast/node is a library enabling usage of Web of Things (WoT) Thing Descriptions (TDs) for Bluetooth devices in Node.js.
Building this library produces 3 files inside the dist directory:
blast.tds.jscontains pre-defined Thing Descriptions of Bluetooth devicesblast.node.jsenables WoT interactions for Bluetooth devices in Node.js, by extending @node-wot/core with node-ble.blast.browser.jsenables WoT interactions for Bluetooth devices in the web, by extending @node-wot/core with Web Bluetooth.
To install and build @blast/core, open a terminal and execute the following commands from withing this directory.
- install the dependencies
yarn install - run the build script
yarn build
Alternatively you could run yarn build:tds, yarn build:node, or yarn build:browser to only build the respective file.
Note
You might have to set yarn version using yarn set version berry before installing
Important
in order to access the Bluetooth HCI layer from Node.js, either you need to run node using sudo every time or execute sudo setcap cap_net_admin=ep $(eval readlink -f `which node`) first to give the node binary access to use Bluetooth HCI.
This section describes using the pre-defined TDs (of dist/blast.tds.cjs) with Node.js using dist/blast.node.cjs. For an example on how to use blast.browser.js see packages/web/. If you don't have a dist folder make sure to install & build first.
import {createThing} from './dist/blast.node.cjs';
import {BleRgbController} from './dist/blast.tds.cjs';
const mac = 'BE5860018744';
const thing = await createThing(BleRgbController, mac);
await thing.writeProperty('colour', {R: 255, G: 0, B: 0});await createThing(td, id)Creates a consumedThing from the provided Thing description and id
| Parameter | Description |
|---|---|
| td | Thing description of the thing to expose |
| id | The things identifier, as a string containing its mac address or the BluetoothDevice.id |
import {createThing} from 'blast.node.js'`Object containg helper methods for interacting with Eddystone devices.
import {EddystoneHelpers} from 'blast.node.js'`| Identifier | Description |
|---|---|
EDDYSTONE_CONFIG_SERVICE |
The BluetoothServiceUUID of the [Eddystone Configuration GATT Service](Eddystone Configuration GATT Service) |
EDDYSTONE_CHARACTERISTICS |
Maps BluetoothCharacteristicUUIDs to their respective Characteristic |
parseCapabilities |
Parses the response of a readProperty operation on the capabilities property and returns an object with human-readable values. e.g parseCapabilities(00040103000fe2ecf0f4f8fc0004) returns { |
| decodeAdvertisingData | Decodes the response of a readProperty operation on the AdvertisingData property and returns a human-readable string. |
| encodeAdvertisingData | Encodes a string using the Eddystone protocol specification for writing it to the AdvertisingData property. |