UNPKG

@stoprocent/bleno

Version:

A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals

29 lines (22 loc) 795 B
/* NOTE: This example no longer works on OSX starting in 10.10 (Yosemite). Apple has apparently blacklisted the battery uuid. */ const bleno = require('../..'); const BatteryService = require('./battery-service'); const 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')); }); } });