ble-server/ble/main-service.js

25 lines
571 B
JavaScript
Raw Normal View History

2017-08-09 10:15:07 +00:00
const bleno = require('bleno')
2017-08-10 01:24:14 +00:00
const config = require('./config.json')
2017-08-23 06:51:42 +00:00
const localEvent = require('./localEvent')
2017-08-09 10:15:07 +00:00
const GdataCharacteristic = require('./gdata-characteristic')
2017-08-23 06:51:42 +00:00
const dataCharacteristic = new GdataCharacteristic()
2017-08-09 10:15:07 +00:00
class MainService extends bleno.PrimaryService {
2017-09-05 10:36:35 +00:00
constructor () {
2017-08-09 10:15:07 +00:00
super({
2017-08-10 01:24:14 +00:00
uuid: config.uuid.service.id,
2017-08-09 10:15:07 +00:00
characteristics: [
2017-08-23 06:51:42 +00:00
dataCharacteristic
2017-08-09 10:15:07 +00:00
]
})
}
}
2017-08-23 15:31:25 +00:00
localEvent.on('printResult', async state => {
let str = state ? 'ok' : 'fail'
2017-08-23 06:51:42 +00:00
dataCharacteristic.sendNotidy(str)
})
2017-08-10 01:24:14 +00:00
module.exports = MainService