update data getter
This commit is contained in:
parent
2d8ba05c84
commit
65f56a6b14
5
app.js
5
app.js
@ -1,6 +1,7 @@
|
||||
const bleno = require('bleno')
|
||||
const config = require('./config.json')
|
||||
const adapterName = 'BLE_Printer'
|
||||
const serverUUID = 'ff9987'
|
||||
const serverUUID = config.uuid.main
|
||||
|
||||
const MainService = require('./main-service')
|
||||
|
||||
@ -24,4 +25,4 @@ bleno.on('advertisingStart', function (error) {
|
||||
console.log('set service', error)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"uuid":{
|
||||
"main": "930da73d-1b80-4d3e-a8b6-d9b4e7e771bd",
|
||||
"service":{
|
||||
"id":"dd535b71-8f05-4e30-beb0-6fa7ea3dfc3e",
|
||||
"func":{
|
||||
|
@ -1,6 +1,8 @@
|
||||
const bleno = require('bleno')
|
||||
const config = require('./config.json')
|
||||
|
||||
var tmp = []
|
||||
|
||||
class DataCharacteristic extends bleno.Characteristic {
|
||||
constructor() {
|
||||
super({
|
||||
@ -18,7 +20,18 @@ class DataCharacteristic extends bleno.Characteristic {
|
||||
onWriteRequest(data, offset, withoutResponse, callback) {
|
||||
console.log(`offset :: ${offset} , withoutRes :: ${withoutResponse}`)
|
||||
console.log(`get data`, data)
|
||||
if (withoutResponse) {
|
||||
|
||||
if(data.length == 1 && data[0] == 0x00){
|
||||
tmp = []
|
||||
console.log(data[0])
|
||||
}else if(data.length == 1 && data[0] == 0xff){
|
||||
//console.log(tmp)
|
||||
console.log(new Buffer(tmp).toString())
|
||||
}else{
|
||||
tmp = [...tmp, ...data.slice(2, data.length)]
|
||||
}
|
||||
if (!withoutResponse) {
|
||||
console.log('send response')
|
||||
callback(this.RESULT_SUCCESS)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user