45

I'm trying to communicate with a BLE module through a Linux machine (the module is running a heart rate profile). So far, I've been able to do everything I need except listening for Notifications and indications (e.g. listening for the Heart Rate Measurement Notification). I'm using kernel version 3.5 and bluez-5.3.

Succcessful commands used so far:

hcitool lescan
hcitool lecc
gatttool -b <Mac Address> --primary
gatttool -b <MAC Address> --characteristics
gatttool -b <MAC Address> --char-read
gatttool -b <MAC Address> --char-desc
gatttool -b <MAC Address> --interactive

Failed commands:

gatttool -b <MAC Address> --listen

Any help is greatly appreciated.

2
  • Did you set the CCC values to get the notifications/indications? Mar 27, 2013 at 20:24
  • I can't find anything about CCC values. The only things that I can control are the psm and mtu. So how do you set CCC values? Mar 28, 2013 at 8:27

5 Answers 5

51

Try this...

Run gatttool -b <MAC Address> --interactive like you did before. You'll get a prompt and then you type connect. You should see a CON in the prompt indicating that you've connected to the device. Then type char-read-uuid 2902. You should get a list of all CCC (Client Characteristic Configuration) attributes on the device. You can try setting them all to 0100 to get notifications, 0200 for indications, 0300 for both, or 0000 for everything off. Type help to see all the commands and their arguments.

EDIT:

The use of the --listen argument requires you to couple it with other commands to turn on the notifications and/or indications. So here's an example that works in Bluez 4.101:

gatttool -b <MAC Address> --char-write-req --handle=0x0031 --value=0100 --listen

Obviously you need to change the handle to the handle of the CCC that you want to turn on notifications for. However, I still find it way easier to just use the interactive mode.

12
  • BTW, the standard says that the CCC values should be retained between connections, but I've used some bluetooth dongles that end up resetting everything between connections. Apr 1, 2013 at 13:03
  • Yes currently everything is resetting for me between connections. However, it's not a problem for me as I can always reset the values to get the notifications. Thanks. Apr 2, 2013 at 14:30
  • @TimTisdall, Thanks. I am trying something similar with a proximity fob. I have been able to write the CCC and read it to confirm, but I am still not seeing notifications using gatttool -b <mac> -t random -I --listen. Do you have any other suggestions? Or am I misunderstanding how it should work?
    – AgDude
    Jun 16, 2013 at 22:59
  • @AgDude some devices require you to set a few variables to get a notification to work. For example, you may have to turn the notifications on in the CCC and then turn on the particular sensor you want to "listen" to. I'm not sure how your's works, but maybe you have to set the proximity alarm level? Jun 17, 2013 at 13:25
  • 5
    @AgDude, For me I had to set the CCC values and listen at the same time. The exact command that I used was gatttool -b <MAC Address> --char-write-req --handle=0xXXXX --value=XXXX --listen Jun 21, 2013 at 9:39
11

Looks like the older version of Bluez (hcitool & gatttool) don't allow you to write to Bluetooth Low Energy devices. I ended up installing a newer version (5.17 as of this writing) in order to enabled notifications, etc.

To get a list of all your handles you can run the following:

char-desc

You can then read from a handle:

char-read-hnd 0x000e

(the above handle is for my nrf51822 battery level)

Where the handle is one from the list you got from char-desc.

Just like Tim said above, you can write to the notification related handle to get indications or notifications. (in my case my device only had notifications)

char-write-req 0x000f 0100

(the above handle is for my nrf51822 battery level notification)

In my case the battery notification shouldn't send anything until the battery level has changed.

I wrote a pretty lengthy blog post on getting setup with Bluez. You can find it here: Get Started with Bluetooth Low Energy Feel free to check it out!

1
  • 1
    The older version works fine for writing to BLE devices. However, it's a little finicky/buggy with the formats. Sometimes it'll except "0x01" but other times it only accepts "01". Jun 4, 2015 at 14:17
6

Final answer for reading heart rate on Mio Alpha :

gatttool -b xx:xx:xx:xx:xx:xx -t random --char-write-req -a 0x0025 -n 0100 --listen

Characteristic value was written successfully
Notification handle = 0x0024 value: 10 4b 33 03 
Notification handle = 0x0024 value: 10 4b 33 03 
Notification handle = 0x0024 value: 10 4b 33 03 
Notification handle = 0x0024 value: 10 4a 3e 03 
Notification handle = 0x0024 value: 10 4c 28 03 28 03 
Notification handle = 0x0024 value: 10 4c 28 03 
Notification handle = 0x0024 value: 10 4b 33 03 
Notification handle = 0x0024 value: 10 4a 3e 03 3e 03
2

to retain the CCC value you need to pair the two device. once they are paired you do not need to set the CCC again. on next reconnection it will find the setting , which will be saved in thec FLASH of Key fob. try to configure after pairing via SMP.

2
  • 1
    How exactly do you do that? Jun 3, 2013 at 21:02
  • 4
    @Tim Tisdall It seems that this can be achieved by increasing the security level of the connection. I tried the following line: #gatttool -l high -b 00:11:22:33:44:55 --primary ,and a notification window poped up asking me to acccept pairing request. Nov 27, 2013 at 13:27
0

gatttool -b B8:F0:09:CC:63:A6 --listen --handle 0x52 --char-write-req --value 0x1

this works even the notification is hidden!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.