蓝牙设备正在接收写请求,我可以在控制台中看到这一点的确认,但是传递的数据变量会产生相同的随机输出,而不管我在数据变量中传递了什么:我猜我是在以错误的格式发送或接收数据变量?
这是我的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 = 158
this._value =?e
等等
发布于 2019-11-20 20:56:06
需要更新布莱诺的新代码。现在修好了。
https://stackoverflow.com/questions/58653224
复制相似问题