Rudimentary BLE peripheral using Node.js and Bleno

I thought I set up a system of my home dialysis devices for automatic collection of data. Blood pressure meassurment devices and scales I’ve looked at use Bluetooth Low Energy to communicate with a central device. I thought I use a Raspberry Pi to scan peripherals and colect data at times of meassurement.

For this, I tried to set up a toy BLE peripheral out of a Raspberry Pi 3B (shipps with Bluetooth 4.1 and Wi-Fi which makes the device much easier to work with than other Pi alternatives).

I started out googling some Python projects as well as some of the litterature (e.g. Getting Started with Bluetooth Low Energy, Tools and Techniques for Low-Power Networking by Kevin Townsend, Carles Cufí, Akiba, Robert Davidson).

Being a total novice on Bluetooth Low Energy, I did not have the chops to take a Python project to fruition. Instead, I found a couple of blog posts and projects using Node.js and Blemo. This was a fast track.

Out of Build a mobile app that connects to your RPi 3 Using BLE by Andreas Lundqvist I found working examples in the GitHub project evothings/evothings-examples and in the Bleno repo.

On the Pi I have the “latest” Stretch Lite (Debian 9.4). The installed bluez is version is 5.43 which works fine with BLE, but before going further we need to shut down the bluez bluetoothd but bring up the host interface

sudo systemctl stop bluetooth
sudo hciconfig hci0 up

Make sure the daemon is “quitting” by issuing

sudo systemctl status bluetooth

Node needs to be installed. I snatched the latest binary, you might need to check the versions available at the site, from NodeJS.org and installed it.

wget https://nodejs.org/dist/latest/node-v9.10.1-linux-armv6l.tar.gz
tar xvfz node-v9.10.1-linux-armv6l.tar.gz
cd node-v9.10.1-linux-armv6l/
sudo cp -R * /usr/local/

Pull down the repos

git clone https://github.com/evothings/evothings-examples.git
git clone https://github.com/noble/bleno.git

Then start a BLE service on the Pi like so

cd evothings-examples/examples/rpi3-system-information/rpi3-application/
npm install
sudo node index.js

I used LightBlue from my MacBook Pro to connect to the Raspberry Pi.

Tinkering with the SysteminformationService it seemed that some component in my “stack” cached information of the service and googling around I found Clearing CoreBluetooth GATT cache without removing bond which made me do

sudo defaults write /Library/Preferences/com.apple.Bluetooth CoreBluetoothCache -dict
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.blued.plist
sudo launchctl load/System/Library/LaunchDaemons/com.apple.blued.plist

This made my Mac and LightBlue update the services and characteristics on the fly.

And I got a toy BLE peripheral for future development.

Leave a comment