@abandonware/bleno
Version:
A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals
29 lines (22 loc) • 786 B
JavaScript
/*
NOTE: This example no longer works on OSX starting in 10.10 (Yosemite). Apple has apparently blacklisted the battery uuid.
*/
var bleno = require('../..');
var BatteryService = require('./battery-service');
var primaryService = new BatteryService();
bleno.on('stateChange', function(state) {
console.log('on -> stateChange: ' + state);
if (state === 'poweredOn') {
bleno.startAdvertising('Battery', [primaryService.uuid]);
} else {
bleno.stopAdvertising();
}
});
bleno.on('advertisingStart', function(error) {
console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));
if (!error) {
bleno.setServices([primaryService], function(error){
console.log('setServices: ' + (error ? 'error ' + error : 'success'));
});
}
});