简体   繁体   中英

Bluez BLE Connection Linux

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:

  1. What is the difference between the two commands?
  2. Would gatttool be suitable for my purpose, or should I work out what's not working with hcitool (following something like this ?
  3. Why does sudo hcitool lecc <bdaddr> partially connect, even when it times out?

Many thanks.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM