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

bleno server not reacting when win 8 device(client) connects #66

Closed
velart opened this issue Aug 26, 2014 · 8 comments
Closed

bleno server not reacting when win 8 device(client) connects #66

velart opened this issue Aug 26, 2014 · 8 comments

Comments

@velart
Copy link

velart commented Aug 26, 2014

Hi! Im using bleno to create bluetooth LE server. Its working well when I connect to server using iOS, Android or Linux devices: all characteristics are seen and free to read or write. On the other hand when im trying to connect from win 8 device, connection process itself goes smoothly but i cant see any characteristics like they appear in this post:
http://sviluppomobile.blogspot.ru/2014/02/ble-for-windows-81-part-i.html
Plus callbacks:
bleno.on('accept', function(clientAddress) {
console.log('on -> accept, client: ' + clientAddress);
bleno.updateRssi();
});
bleno.on('disconnect', function(clientAddress) {
console.log('on -> disconnect, client: ' + clientAddress);
});
doesn`t react like they do when im connecting using other devices.

Please help me to identify the problem and establish working ble connection with win 8. If u need I can add my code.

P.S. Sorry for my bad english.

@sandeepmistry
Copy link
Collaborator

@velart this is the first time I've heard of someone try from win 8 ...

Could you please run with debug on and create a Github Gist for the output:

sudo DEBUG=l2cap-ble node <file>.js

This way I can see what commands the windows device is sending. Btw, have you tried using an iOS as a peripheral and connecting to it with Windows?

@velart
Copy link
Author

velart commented Sep 1, 2014

@sandeepmistry, thank you for your response.
I tried to ran debug. But before you look at it I first want to explain how bluetooth LE connection process with win 8 actually goes. To make it work you need first to pair(!) and only then connect your device to windows. And u can do it only using windows native UI cause there doesnt exist any open APIs to write your own code... The most funny part is that there are two situations which may happen while trying to connect devices:

  1. devices first exchange passkeys(pairing confirment) and then ble server device accepts connection. Its situation there connection get established but callbacks I mentioned dont react and characteristics don`t appear(it seems like nothing appear in debug logs too)
  2. second situation appears really rear. About 1/15 chance of all attempts to connect. Windows require to type password which is generated in ble server device. I type password and then devices are starting attempt to connect and i`m getting error on both devices. On the other hand something appears in the debug logs.

https://gist.github.com/Velart/38ae15a9747aba9475aa

I tried to use iOS device as peripheral but Windows dont want to paire up with iOS so i cant establish connection...

@sandeepmistry
Copy link
Collaborator

@velart the 2nd debug log is very useful! In summary, windows 8 tries to negotiate an MTU of 3300 bytes (0x0d02) and bleno accepts even though the max MTU l2cap-ble expects is 256 bytes.

I've pushed a change to limit the MTU between 23 - 256 bytes (13c2807). Please try the latest from Github, and report back ...

npm install sandeepmistry/bleno

Break down of 2nd debug log:

// MTU 3330
02 0d02
03 0d02


// discover services
//   0x1800
//   0x0000180d00001000800000805f9b34fb
10 0100 ffff 0028
11 06 0100 0500 0018

10 0600 ffff 0028
11 14 0600 8100 fb349b5f80000080001000000d180000 

10 8200 ffff 0028
01 10 8200 0a

// read uuid 0x2802 - included services
//   none
08 0100 0500 0228
01 08 0100 0a

// read uuid 0x2803 - characteristics
//   0x2a00
//   0x2a01
08 0100 0500 0328
09 07 0200 02 0300 002a 0400 02 0500 012a 

// read handle 0x003 (device name)
//   'roger-Lenovo-B560'
0a 0300
0b 726f6765722d4c656e6f766f2d42353630

// read handle 0x005 (flags)
//    128
0a 05 00
0b 8000

// read uuid 0x2802 - included services
//   none
08 0600 8100 0228
01 08 0600 0a

// read uuid 0x2803 - characteristics
//   BOOM! - past 256 byte max mtu size
08060081000328
0915070008080004c187aa03aa148d0740a4383bf6c0490900080a006fa9f3a07d86ffbc5449f1f458f5a1f40b00080c004ebef92d835824a1394a7d59b5e11eb30d00080e0069a36a17d0876ca92146e1f505545f870f00081000f744e342b82761a50d45e6722806dab71100081200caa36b1f4803a88655417a577418a0e71300081400620dad9dcbd86a88444e1ad6a1cd6c691500081600e65155539799cb83804d78ef44aa37c61700081800ad89ef01fb0c8d9bf644e4eb99ccf1261900081a00705ef8fe482f6ab15847f830d3bb4aa01b00081c00b950d0bdec124aa5774a09b94dda22ae1d00121e00e44c0293a51a46b9ae48ede63dc8e5552200102300afef06b845d1bc973d4e60cc09f3d23925000226007db6d0423b53ecb350408939867897962a00022b0043b016c7b8923f8dd64f48ed3a9390ac2f00023000ef65eeb090b5d5925445efc407281e5a34000235001d3d557652294ca7ba46ce01e9c30d7f3900023a00dbfd9758276491befa40f10fb13096653e00023f002f32d13fe9c8e9b2d14eefbe9cef344b430002440075a887d9967eb8a92d4f854bce1bc1674800024900a7b1dc8d30deec8e214fa46e298b00354d00024e0026907bd9ab94f3acb9429100ef8bf6c152000253004ccba2bf7de4519b454a15276fa4928e57001058005926c078dae9d98b28470e972b3bad16

@velart
Copy link
Author

velart commented Sep 2, 2014

Thank you! It worked like a charm!
The only problem left is to understand why windows connects to ble server in 2 different ways. It becomes real pain to connect the second way cause today it happened only after 50 attempts. And first way connection is good-for-nothing.
One clue I got is that the second type connection establishes with the name of my notebook(linux username) and first type with the name I set in bleno advertising.

@sandeepmistry
Copy link
Collaborator

@velart cool!

The notebook name is determined from the hostname, to "discover" it, Windows would need to connect to the peripheral and read the 0x2a00 characteristic: https://github.com/sandeepmistry/bleno/blob/master/lib/linux/l2cap-ble.js#L146

Can this issue be closed? It looks like it's a Windows issue after I fixed the MTU range in bleno ...

@velart
Copy link
Author

velart commented Sep 3, 2014

Yes, issue can be closed. Thank you for your help.

@velart
Copy link
Author

velart commented Sep 29, 2014

Please, publish your patch on official npm server because I use your library in project which installs all dependencies via package.json

@sandeepmistry
Copy link
Collaborator

@velart 0.1.8 is published!

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

2 participants