Domanda

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.

È stato utile?

Soluzione

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.

Altri suggerimenti

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!

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

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top