noble / bleno

A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals
MIT License
2.12k stars 447 forks source link

How to set the flags and value of the data used in a particular Bluetooth Profile? For eg .Weight Scale Measurement Characteristic in Weight Scale Service #414

Open Ajinkya236 opened 5 years ago

Ajinkya236 commented 5 years ago

WeightScaleCharacteristic.prototype.onSubscribe = function(maxValueSize, updateValueCallback) { console.log('IndicateOnlyCharacteristic subscribe');

this.counter = 1; this.changeInterval = setInterval(function() {

var flag= new Buffer(2); var value=new Buffer(50);

var weightValue=Math.floor((Math.random()*19000)+1); if(weightValue<12000){ weightValue+=9000; }

flag.writeInt16BE(0);

value.writeInt16BE(weightValue);

var arr=[flag,value];

var buff=Buffer.concat(arr);

updateValueCallback(buff);

console.log(' WeightScaleCharacteristic-IndicateRequest : Value = ' + buff +' Count=' + this.counter);

this.counter++;

}.bind(this), 1000); };

WeightScaleCharacteristic.prototype.onUnsubscribe = function() {

console.log('IndicateOnlyCharacteristic unsubscribe');

if (this.changeInterval) { clearInterval(this.changeInterval); this.changeInterval = null; } };

WeightScaleCharacteristic.prototype.onIndicate= function() {

console.log('IndicateOnlyCharacteristic on Indicate'); };