Reputation: 1137
I'm very new to Linux and Bluetooth development, and I'm unsure of the difference between sudo hcitool lecc <bdaddr>
and sudo gatttool -b <dbaddr> -I
? I don't require any of the GATT services; I just want a connection between the two devices.
I'm looking at vaguely following this widely referred to tutorial, and am looking at adapting the cmd_lecc
method in Bluez /tools/hcitool.c, but I am unable to connect to my BLE device using hcitool lecc
.
When I connect using gatttool
, I am able to connect successfully, however using hcitool lecc
returns the error 'Could not create connection: Connection timed out', and no connection is made to the BLE device. However, running sudo hcitool con
to show active connections shows that there is one: 'Unknown handle 0 state 2 lm SLAVE'. If it's failing to make the connection, why is it then registering the connection as active in hcitool
?
My question therefore is threefold:
gatttool
be suitable for my purpose, or should I work out what's not working with hcitool
(following something like this?sudo hcitool lecc <bdaddr>
partially connect, even when it times out?Many thanks.
Upvotes: 3
Views: 4225
Reputation: 435
hcitool lecc <bdaddr>
creates a connection and returns a handle, while gatttool -b <bdaddr> -I
only opens an interactive terminal with an interface bound to the address but not yet connected. To connect using the gatttool
command you must then enter connect
, which will most likely also fail.
I would suggest looking at how hcitool
connects for writing your own code as all of gatttool
simply is a wrapper around the same process that hcitool
uses, but its wrapper is not available unless you copy its code.
lastly, the handle 0 that hcitool
is reporting is an invalid handle left from trying to connect, because as far as I've seen all valid handles are greater than 0.
Upvotes: 1