Maker Faire NY - Sept 27, 2015
Don Coleman - Chariot Solutions
Can be expanded to 128 bit UUIDs
0000FF10-0000-1000-8000-00805F9B34FB
0000FF11-0000-1000-8000-00805F9B34FB
0000FF12-0000-1000-8000-00805F9B34FB
A Node.js module for implementing BLE peripherals.
github.com/sandeepmistry/bleno
$ cd path/to/project
$ npm install bleno
var Gpio = require('onoff').Gpio,
led = new Gpio(18, 'out');
var bleno = require('bleno');
var util = require('util');
var SwitchCharc = function() {
SwitchCharc.super_.call(this, {
uuid: 'ff11',
properties: ['read', 'write']
});
};
util.inherits(SwitchCharc, Characteristic);
SwitchCharc.prototype.onReadRequest
= function(offset, callback) {
var data = new Buffer(1);
data[0] = led.readSync();
callback(this.RESULT_SUCCESS, data);
};
SwitchChar.prototype.onWriteRequest
= function(data, offset,
withoutResponse, callback) {
led.writeSync(data[0]);
callback(this.RESULT_SUCCESS);
}
var lightService = new PrimaryService({
uuid: 'ff10',
characteristics: [
new SwitchCharc()
]
});
bleno.on('stateChange', function(state) {
if (state === 'poweredOn') {
bleno.startAdvertising('LED', ['FF10']);
} else {
bleno.stopAdvertising();
}
});
bleno.on('advertisingStart', function(err) {
if (!err) {
bleno.setServices([lightService]);
}
});
A Node.js BLE central module.
github.com/sandeepmistry/noble
$ cd path/to/project
$ npm install noble
Be sure to check out the Getting Started guide.
sudo rpi-update \
46d179597370c5145c7452796acbee0f1ff93392
More info see rpi-update &
rpi-firmware
var Gpio = require('onoff').Gpio,
button = new Gpio(23, 'in', 'both');
var noble = require('noble');
noble.on('stateChange', function(state) {
if (state === 'poweredOn') {
noble.startScanning(['ff10']);
} else {
noble.stopScanning();
}
});
noble.on('discover', function(peripheral) {
console.log(peripheral);
connectAndSetUp(peripheral);
});
function connectAndSetUp(peripheral) {
peripheral.connect(function(error) {
var serviceUUIDs = ['ff10'];
var characteristicUUIDs = ['ff11'];
peripheral.discoverSomeServicesAndCharacteristics(
serviceUUIDs, characteristicUUIDs,
onDiscovered);
});
}
function onDiscovered(err, services, characteristics) {
function sendData(byte) {
var buffer = new Buffer(1);
buffer[0] = byte;
characteristics[0].write(buffer);
}
button.watch(function(err, value) {
console.log("button " + value);
sendData(value);
});
}
github.com/sandeepmistry/node-bleacon
Don Coleman
Slides don.github.io/slides/
Code github.com/don/mfny2015-rpi-ble
Bluetooth Low Energy with Raspberry Pi by Don Coleman
is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at https://github.com/don/.../2015-09-27-rpi-ble.