ble-server/ble/index.js
2017-09-05 18:36:35 +08:00

26 lines
719 B
JavaScript

const config = require('../config.json')
const bleno = require('bleno')
const adapterName = 'BLE_Printer'
const serverUUID = config.uuid.main
const localEvent = require('./localEvent') //eslint-disable-line
const MainService = require('./main-service')
bleno.on('stateChange', state => {
console.log(`bt device state ${state}`)
if (state === 'poweredOn') {
bleno.startAdvertising(adapterName, [serverUUID])
} 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)
})
}
})