-
Notifications
You must be signed in to change notification settings - Fork 161
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
gattlib_connect does not succeed all the time when it should #2
Comments
@cryptax I have just added proper Bluez5 support (based on Bluez 5.43). I would be curious to know whether you still have the issue. |
I experience something similar. Often the connects fails, but when it succeeds a GLib_Warning is also printed (gattlib-master as of 2017-02-11, on RaspberryPi3, BlueZ 5.43). E.g. ./read_write 20:CD:39:B1:8E:E3 read "00002a19-0000-1000-8000-00805f9b34fb" (process:3406): GLib-WARNING **: Invalid file descriptor. ./read_write 20:CD:39:B1:8E:E3 read "00002a19-0000-1000-8000-00805f9b34fb" (Sometimes the read just 'hangs' foever after having printed the read value...) |
I know about the warning. It should be harmless even if I am planning to fix it at some point. Does |
I'll try to experiment with the 2s timeout. Here's some additional data. //Using (built-in) gattool (huge variation in response times, but always reports back - large response times could easily be a problem with the device/Adapter) real 0m0.409s ... 7 subsequent calls: // Using gatlib (Many fails, could very well be related to the 2s timeout) (process:30282): GLib-WARNING **: Invalid file descriptor. real 0m1.715s ... 5 subsequent calls: |
Tried to change the CONNECTION_TIMEOUT to 6 (and rebuild), provided the same 'picture' as before.. with many connection-fails, just with a longer timeout period (~CONN_TIMEOUT+4) $ sudo hciconfig hci0 down; sudo hciconfig hci0 up (process:30476): GLib-WARNING **: Invalid file descriptor. real 0m0.429s Subsequent calls: (I also did 10 calls with gatttool, and none failed. Timing was avg. < 1.1s) Finally changing the CONNECTION_TIMEOUT to 12 just resulted in failed connects after ~16s (Pattern was again the same. First connect is often OK, subsequent calls fail except a few) |
As I told stepen in another issue I have just fixed |
@stepen , do you mind doing the same test with the ported
|
With this following source file I have almost 100% success (I have not tried
|
Here is some additional data. Run #1: NEW gattlib-gatttool, Device=20:CD:39:B1:8E:E3: 59 calls, 9 fail-to-read, 3 resource busy. I've only included data for run #1 and run#2. And as I said earliere, it MIGHT well be a problem with the actual device (20:CD:39:B1:8E:E3=prototype), which the results partly hints at.
Never recovers from this. 'bluetoothctl' (info 20:CD:39:B1:8E:E3) reports device as 'connected = yes'. Which explains the error, but not why it occured in the first place.
|
Sorry, I cannot reproduce this issue with the only BLE device I have here. :-( |
The time it takes to connect does seem to be unbearably slow, compared to the regular gatttool |
I cannot duplicate the issue with my Nordic nRF52 board. default gatttool
Gattlib gatttool
Gattlib read_write
|
I am doing it on the Raspberry Pi 3, but I still get some very slow connection. |
I am having similar problems, and one thing I noticed while trying to debug the problem is that after a gattlib_disconnect the device is disconnected (it starts advertizing again), but bluez thinks it is still connected ("hcitool con" shows the device as still connected) |
Playing around some more, it looks like this problem has more to do with gattlib/bluez not properly disconnecting so when an attempt is made to re-connect, there is one of a couple (few?) different connection problems that can happen |
The code posted by @oliviermartin would not compile for me... but I noticed the main difference as why it works. It does not have to do with the async method or not (which the async is really nice to have). It has to do with the BDADDR_LE_RANDOM flag. The issue is that from my blueZ version 4.101 I can only connect to devices with the -t random parameter. I hope this solves the problems for everyone having the same issue! I changed the flag/parameter on the discover example and it work great. The ble_scan needs a bit more modifications for it to work right, but I have not need for it currently since I know the device address I want to connect to.
Here is the main method on the updated read_write.c `
` |
I wrote a program using gattlib that connects to a BLE device. Unfortunately, although the device is in a correct state, the connection fails many times before it eventually works. I consequently have to perform several connection attemps before I actually manage to connect.
This issue does not occur when I use gatttool: I always connect (perhaps sometimes a bit longer) provided my device/host/dongle is in a normal state of course.
That's the piece of code I use for connection:
Sample output of my program:
Why is that? Is there a way I can change some settings etc so that the connection always succeeds (provided the device is there ;)?
For example, with
gatttool
:I have bluez 5.37 and the latest checkout of gattlib.
The text was updated successfully, but these errors were encountered: