ble-server/app.js

29 lines
676 B
JavaScript
Raw Normal View History

2017-08-09 10:15:07 +00:00
const bleno = require('bleno')
2017-08-10 12:18:43 +00:00
const config = require('./config.json')
2017-08-09 10:15:07 +00:00
const adapterName = 'BLE_Printer'
2017-08-10 12:18:43 +00:00
const serverUUID = config.uuid.main
2017-08-09 10:15:07 +00:00
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)
})
}
2017-08-10 12:18:43 +00:00
})