Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'index out of range' when central tries to unsubscribe #23

Closed
empinator opened this issue Feb 1, 2014 · 7 comments
Closed

'index out of range' when central tries to unsubscribe #23

empinator opened this issue Feb 1, 2014 · 7 comments

Comments

@empinator
Copy link

Hi,

I wrote a notifier service based on the given examples, but when noble is trying to unsubscribe from bleno's with this command:
characteristic.notify(false, notify._notifyDisable);

bleno is crashing with an 'index out of range'

buffer.js:604
    throw new RangeError('index out of range');
          ^
RangeError: index out of range
    at checkInt (buffer.js:604:11)

Peripheral:
Machine: Raspberry PI, Kernel 3.6.11+, Bluez 5.8, GBU521 Dongle
code: http://pastebin.com/bpUBihb5
console output: http://pastebin.com/2qwBY91p

Central:
Machine: Thinkpad T400s, Kernel 3.5.0-45-generic, Bluez 5.8, GBU521 Dongle
code: http://pastebin.com/Esa5xhvz
console output: http://pastebin.com/jZ81CgMM

any idea?
Thanks.

@empinator
Copy link
Author

not being able to figure out the deeper reason behind to that issue, I at least modified a piece of code which removes the symptom

in lib/linux/l2cap-ble.js around line 650. When data is not of type Buffer I am converting it

...
    var data = this._handles[valueHandle].value;

    if(typeof data != "object"){
        console.log('data', data);
        var tdata = new Buffer(4);
        tdata.writeUInt32LE(data);
        data = tdata;
    }
    var dataLength = Math.min(data.length, this._mtu - 4);
...

@sandeepmistry
Copy link
Collaborator

@empinator sorry I haven't had a chance to look at your sample code, it's on my list of things to look at.

Can you console.log: data, data.length, and this._mtu here - one of them is causing the Buffer to be smaller than it should be (maybe a negative value).

@empinator
Copy link
Author

        console.log('data', data);
        console.log('data.length', data.length);
        console.log('this._mtu', this._mtu);

->

data 1
data.length undefined
this._mtu 256

I know how it is having a project on the side which is fun but still not your day job :-)
Don't worry about not answering immediately, I am glad you do though.

@sandeepmistry
Copy link
Collaborator

I think I found the problem, when notify is enabled/disabled, the value is not stored as a Buffer.

Try changing, l2cap-ble.js line 820:

handle.value = value;

to

handle.value = data;

@sandeepmistry
Copy link
Collaborator

@empinator this should be fixed now, with the commit above, let me know if you have any issues.

@empinator
Copy link
Author

awesome, thank you

@paixaop
Copy link

paixaop commented Aug 30, 2018

I also faced a similar problem but in my case the error was in my code the call to writeUInt32LE needs 4 bytes and I had initialized the value to a single byte buffer with Buffer.alloc(1).

Changing it to value: Buffer.alloc(4) in the appropriate characteristic class solved the issue.

new Bleno.Descriptor({
     // Client Characteristic Configuration
     uuid: '2902',
     value: Buffer.alloc(4)
}),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants