ble-server/ble/index.js
Jay a7f7653efa 修改服務啟動動作與QRCode產生按鈕
1.啟動時連接印表機
2.判斷是否要開啟藍芽
3.畫面加入QRCode產生按鈕,方便APP設定
2017-09-07 23:41:56 +08:00

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)
})
}
})