写入特性 - Nodejs、Bleno、蓝牙

Write Characteristic - Nodejs, Bleno, Bluetooth

蓝牙设备正在正常接收写入请求,我可以在控制台中看到确认,但是无论我在数据变量中传递什么,传递的数据变量都会产生相同的随机输出:我猜我发送或接收的数据变量格式有误?

这是我的 Android 设备的代码,向蓝牙设备发送写入请求

var data = new Uint8Array(2);
//var data = new Uint8Array([21,31]);  // also tried many versions of this

Object.keys(app.SENDWRITE).map(
function(characteristic){
    device.writeCharacteristic(
        characteristic,
        app.SENDWRITE[characteristic],
        data,
        function(error){console.log('Error occured')
        }
    );
});

这是接收请求的蓝牙设备上的代码:

var bleno = require('bleno');
var os = require('os');
var util = require('util');

var BlenoCharacteristic = bleno.Characteristic;

var SomeCharacteristic = function() {
    SomeCharacteristic.super_.call(this, {
        uuid: 'THE_UUID',
        properties: ['write'],
    });

    this._value = new Buffer(0);
};

SomeCharacteristic.prototype.onWriteRequest = function(data, offset, withoutResponse, callback) {

    this._value = data;

    console.log('Date Received from Write Request: value = ' + this._value[0]);
   //console.log('Date Received from Write Request: value = ' + this._value);
//console.log('Date Received from Write Request: value = ' + this._value.toString('utf8'); // tried many versions of this

  callback(this.RESULT_SUCCESS);
};

util.inherits(SomeCharacteristic, BlenoCharacteristic);
module.exports = SomeCharacteristic;

不同的输出结果:
this._value[0] = 158
this._value = ??e
等等等等等等

需要来自 bleno 的新更新代码。现已修复。