简体   繁体   English

写特性——Nodejs、Bleno、蓝牙

[英]Write Characteristic - Nodejs, Bleno, Bluetooth

The bluetooth device is receiving the write request just fine, and I can see confirmation of that in the console, however the data variable being passed is resulting in the same random output no matter what I pass in the data variable: I'm guessing I'm either sending or receiving the data variable in the wrong format?蓝牙设备正在接收写入请求就好了,我可以在控制台中看到确认,但是无论我在数据变量中传递什么,传递的数据变量都会导致相同的随机 output:我猜我'以错误的格式发送或接收数据变量?

Here is the code from my Android Device, sending a write request to the Bluetooth Device这是来自我的 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')
        }
    );
});

Here is the code on the bluetooth device receving the request:这是接收请求的蓝牙设备上的代码:

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;

Different output results:不同的 output 结果:
this._value[0] = 158 this._value[0] = 158
this._value =??e this._value =??e
etc, etc, etc.等等等等等等。

New updated code from bleno was needed.需要来自 bleno 的新更新代码。 Fixed now.现在修好了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM