5

I would like to connect to a Bluetooth Low Energy (BTLE, Bluetooth Smart) device using a linux box with bluez and a bluetooth dongle. I have Orico BTA-402 dongle with CSR chipset; Ubuntu 14.04. I figured out how to make it the dongle appear as a device to a phone (hciconfig hci0 leadv 3).

What I would like is the opposite, for the dongle/linux box to scan for devices, connect to a device, enumerate characteristics, and read/write them. How do I do that?

3 Answers 3

3

The hcitool lescan answer is incomplete. it will loop. You want a timeout, but a timeout that will not cause issue to hcitool (the default signal would)

For 5 seconds:

timeout -s SIGINT 5s hcitool -i hci0 lescan --passive

Then you can use gatttool:

sudo gatttool -i hci1 -b BC:6A:29:AC:2E:B4 -I

For more details on what to do after the connect: http://joost.damad.be/2013/08/experiments-with-bluetooth-low-energy.html

2

Was demonstrated by jaredwolff you can use hcitool

hcitool lescan

Your device should show up like that: F4:C7:F8:0A:BF:C9 TWI. If don't show up, maybe it (the device that you are searching) isn't advertising itself.


To connect to a device you can use gatttool interative mode:

$ gatttool -I
[                 ][LE]> connect <BLE ADDRESS>

Inside gatttool you can use char-desc to obtain the available handles, char-read-hnd to read and char-write-req to write, see help to more details.

4
  • Thanks! Could you post an example of a gatttool session that uses char-desc and char-write-req?
    – Alex I
    Commented Oct 15, 2016 at 21:33
  • You can find one in the link: jaredwolff.com/blog/get-started-with-bluetooth-low-energy or learn.adafruit.com/…
    – a0f3dd13
    Commented Oct 15, 2016 at 21:36
  • Also, is there a way to use gatttool for the same thing in non-interactive mode?
    – Alex I
    Commented Oct 15, 2016 at 21:38
  • Yes, just remove the -I for non-interactive mode, and use the commands shown in gatttool --help-gatt.
    – a0f3dd13
    Commented Oct 15, 2016 at 21:43
1
hciconfig hci0 up piscan  

(assuming that 'hci0' is the device name for your bluetooth dongle)

The switch 'piscan' enables both 'pscan' and 'iscan'.

Excerpt from manpage:

piscan Enable page and inquiry scan.

noscan Disable page and inquiry scan.

iscan Enable inquiry scan, disable page scan.

pscan Enable page scan, disable inquiry scan.

1
  • 1
    That's for BlueTooth classic, no? The question was about BlueTooth LE (also called BlueTooth Smart).
    – jch
    Commented Jul 29, 2016 at 12:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .