barnowl-hci
v0.4.0
Published
Collect ambient advertising packets from the Bluetooth Host Controller Interface (HCI) for real-time location and sensing. We believe in an open Internet of Things.
Downloads
44
Maintainers
Readme
barnowl-hci
barnowl-hci converts the decodings of any ambient Bluetooth Low Energy devices from a local Bluetooth Host Controller Interface (HCI) into standard developer-friendly JSON that is vendor/technology/application-agnostic.
barnowl-hci is a lightweight Node.js package that can run on resource-constrained edge devices. It can forward data to reelyActive's Pareto Anywhere open source middleware suite, and can just as easily be run standalone behind a barnowl instance, as detailed in the code examples below.
Quick Start
Clone this repository and install package dependencies with npm install
. If installation fails on your system, validate these installation requirements.
Then from the root folder run at any time:
npm start
If you observe a permissions error (ex: EPERM), either assign the necessary privileges (recommended) or run as root (not recommended). barnowl-hci will set the local Bluetooth radio to scan and print any processed raddec data to the console.
Hello barnowl-hci!
The following code will listen to simulated hardware and output packets to the console:
const BarnowlHci = require('barnowl-hci');
let barnowl = new BarnowlHci();
barnowl.addListener(BarnowlHci.TestListener, {});
barnowl.on("raddec", function(raddec) {
console.log(raddec);
});
barnowl.on("infrastructureMessage", function(message) {
console.log(message);
});
As output you should see a stream of raddec objects similar to the following:
{
transmitterId: "001122334455",
transmitterIdType: 2,
rssiSignature: [
{
receiverId: "000000000000",
receiverIdType: 2,
rssi: -69,
numberOfDecodings: 1
}
],
packets: [ '421655daba50e1fe0201050c097265656c79416374697665' ],
timestamp: 1547693457133
}
Regardless of the underlying RF protocol and hardware, the raddec specifies what (transmitterId) is where (receiverId & rssi), as well as how (packets) and when (timestamp).
Is that owl you can do?
While barnowl-hci may suffice standalone for simple real-time applications, its functionality can be greatly extended with the following software packages:
- advlib to decode the individual packets from hexadecimal strings into JSON
- barnowl to combine parallel streams of RF decoding data in a technology-and-vendor-agnostic way
These packages and more are bundled together as the Pareto Anywhere open source middleware suite, which includes several barnowl-x listeners.
Supported Listener Interfaces
The following listener interfaces are supported.
Socket
Listen on a local Bluetooth HCI interface. Check the bluetooth-hci-socket package for prerequisites specific to the target platform. Note that not all platforms are supported. It may be required to grant additional user privileges, or else run as super user (at your own risk).
let options = { enableActiveScanning: false,
scanIntervalMilliseconds: 10,
scanWindowMilliseconds: 10 };
barnowl.addListener(BarnowlHci.SocketListener, options);
The default options are shown above. Note that, according to the Bluetooth Core Specification:
- valid interval & window durations are in the range of 2.5ms to 10.24s
- the window duration cannot exceed the interval duration
Test
Provides a steady stream of simulated reel packets for testing purposes.
barnowl.addListener(BarnowlHci.TestListener, {});
Pareto Anywhere Integration
barnowl-hci includes a script to forward data to a local Pareto Anywhere instance as UDP raddecs with target localhost:50001. Start this script with the command:
npm run forwarder
See our Run Pareto Anywhere on a Raspberry Pi and Run Pareto Anywhere on a PC tutorials for instructions on how to run barnowl-hci as a systemd service on boot on a Raspberry Pi or PC, respectively.
To instead forward UDP raddecs to a remote Pareto Anywhere instance, start this script with the command:
npm run forwarder xxx.xxx.xxx.xxx
where xxx.xxx.xxx.xxx is the IP address of the remote instance.
Assigning Privileges
To start a scan without root privileges, it is necessary to grant cap_net_raw privileges. For instance, to grant privileges to Node.js so that any Linux user may start a scan, run the following:
sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)
Installation Requirements
barnowl-hci depends on the bluetooth-hci-socket package which does not support all operating systems. If your OS is supported but a precompiled binary does not exist, npm will attempt to compile the binary using node-gyp (which may need to be installed).
On Ubuntu/Debian Linux distributions, if node-gyp throws errors during installation, the make and g++ prerequisites for compilation may need to first be installed with sudo apt install make
and sudo apt install build-essential
respectively.
Project History
barnowl-hci is based on the bluetooth-hci-socket package which has been forked and maintained by various members of the open source community since 2015. The initial versions of barnowl-hci were based on Sandeep Mistry's original bluetooth-hci-socket. The @abandonware/bluetooth-hci-socket fork, which was adopted in 2019, can be found in the release-0.3 branch. And the @stoprocent/bluetooth-hci-socket fork, actively maintained at the time of writing, is currently used.
Contributing
Discover how to contribute to this open source project which upholds a standard code of conduct.
Security
Consult our security policy for best practices using this open source software and to report vulnerabilities.
License
MIT License
Copyright (c) 2018-2024 reelyActive
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.