node.jscharacteristicsbleno

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?

Here is the code from my Android Device, sending a write request to the Bluetooth Device

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:
this._value[0] = 158
this._value = ??e
etc, etc, etc.


Solution

  • New updated code from bleno was needed. Fixed now.