25 lines
658 B
JavaScript
25 lines
658 B
JavaScript
const config = require('../config.json')
|
|
const bleno = require('bleno')
|
|
const adapterName = 'BLE_Printer'
|
|
const serverUUID = config.ble.uuid.main
|
|
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)
|
|
})
|
|
}
|
|
})
|