const bleno = require('bleno') const config = require('./config.json') var tmp = [] class DataCharacteristic extends bleno.Characteristic { constructor() { super({ uuid: config.uuid.service.func.data, properties: ['write', 'writeWithoutResponse'], descriptors: [ new bleno.Descriptor({ uuid: '8888', value: 'Now' }) ] }) } onWriteRequest(data, offset, withoutResponse, callback) { console.log(`offset :: ${offset} , withoutRes :: ${withoutResponse}`) console.log(`get data`, data) 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) } } } module.exports = DataCharacteristic