Turn your Mac into a BLE Peripheral Device
This guide will show you how to turn your Mac into a Bluetooth Low Energy (BLE) peripheral device for creating your very own BLE services and characteristics.
Steps
- Check if you have node.js installed already
In Terminal, run this command:node --version
-
Install node.js on your Mac
Go to the Node.js website
Download the installer for the latest LTS version (v6.11.2 LTS at the time of writing)
Follow the installer prompts -
Download example files from the bleno github repo Echo example
It includes two files: main.js & characteristic.js
Place these 2 files by themselves in a folder somewhere -
In Terminal, navigate to the folder containing your main.js and characteristic.js files
- Use Node Package Manager (npm) to install bleno in that directory
Run this command in Terminal:npm install bleno
- In Terminal, run the main.js script to start advertising your device
node main.js
- Open a BLE app, like LightBlue to view your device, its services and characteristics
LightBlue for iOS
LightBlue for MacOS
Any value you write to the Echo Characteristic (UUID: 0xEC0E) on the device should be echoed in the Terminal window
Output in Terminal:
State: poweredOn
on -> advertisingStart: success
EchoCharacteristic - onUnsubscribe
EchoCharacteristic - onWriteRequest: value = ab
EchoCharacteristic - onReadRequest: value = ab
To quit the node program, press Control + C
For more info, see the bleno github page
Enjoy!