diff --git a/gdata-characteristic.js b/gdata-characteristic.js index 1a80861..ce4c359 100644 --- a/gdata-characteristic.js +++ b/gdata-characteristic.js @@ -11,18 +11,21 @@ device.open(()=>{ var tmp = [] +const notifyDesciptor = new bleno.Descriptor({ + uuid: '8888', + value: 0 +}) + class DataCharacteristic extends bleno.Characteristic { constructor() { super({ uuid: config.uuid.service.func.data, - properties: ['write', 'writeWithoutResponse'], + properties: ['write', 'writeWithoutResponse', 'notify'], descriptors: [ - new bleno.Descriptor({ - uuid: '8888', - value: 'Now' - }) + notifyDesciptor ] }) + this._notifyFunc = null } onWriteRequest(data, offset, withoutResponse, callback) { @@ -36,6 +39,9 @@ class DataCharacteristic extends bleno.Characteristic { //console.log(tmp) console.log(Buffer.from(tmp).toString()) printString(Buffer.from(tmp).toString()) + if(this._notifyFunc) { + this._notifyFunc(Buffer.from([0x00,0x01])) + } } else { tmp = [...tmp, ...data.slice(2, data.length)] } @@ -44,6 +50,15 @@ class DataCharacteristic extends bleno.Characteristic { callback(this.RESULT_SUCCESS) } } + + onSubscribe(maxValueSize, cb) { + console.log(maxValueSize) + this._notifyFunc = cb + } + + onUnsubscribe () { + this._notifyFunc = null + } }