ble-server/app.js
2017-08-10 20:18:43 +08:00

29 lines
676 B
JavaScript

const bleno = require('bleno')
const config = require('./config.json')
const adapterName = 'BLE_Printer'
const serverUUID = config.uuid.main
const MainService = require('./main-service')
bleno.on('stateChange', state => {
console.log(`bt device state ${state}`)
if (state == 'poweredOn') {
bleno.startAdvertising(adapterName, [serverUUID], (error) => {
})
} else {
bleno.stopAdvertising()
}
})
bleno.on('advertisingStart', function (error) {
console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));
if (!error) {
bleno.setServices([new MainService()], error => {
console.log('set service', error)
})
}
})