编写特征-Nodejs,Bleno,蓝牙

时间:2019-11-01 01:54:09

标签: node.js characteristics bleno

蓝牙设备很好地接收了写入请求,我可以在控制台中看到对它的确认,但是无论我传递数据变量是什么,传递的数据变量都会导致相同的随机输出:我猜我是以错误的格式发送或接收数据变量吗?

这是我的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
等,等等。

1 个答案:

答案 0 :(得分:0)

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