Bluetooth Low Energy: Listening For Notifications/Indications in Linux

Bluetooth Low Energy: listening for notifications/indications in linux

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.

Using Bluetooth low energy in linux command line

SDP is absent in BLE. Broadcast/advertise frame and GATT client/server are used instead.

Several links:

  • BlueZ gatttool: command line tool to run common GATT procedures
  • BlueZ GATT's ready profiles
  • hint: DBUS
  • GATT and DBUS example
  • How can I connect to the FitBit Zip over Bluetooth 4.0 LE on Linux with bluez?
  • Bluetooth Low Energy: listening for notifications/indications in linux
  • http://comments.gmane.org/gmane.linux.bluez.kernel/29547

Reading Thermometer Data with Bluez Bluetooth Low Energy

Assuming that your device uses the adopted thermometer profile, then you want to enable indications on the temperature measurement characteristic. To do this, there are several steps:-

  1. Find the handle of the temperature characteristic using:-

    gatttool -b 00:11:22:33:44:55 --characteristics

Replace 00:11:22:33:44:55 with the Bluetooth address of your device. You basically want to find the uuid that contains 2a1c and note down its corresponding 'char value handle'.


  1. Find the descriptors at that handle using

    gatttool -b 00:11:22:33:44:55 char-desc --handle=0xXX

Where XX is the char value handle that you noted down earlier. You should be able to see a couple of characteristic descriptors at that handle. Note down the char handle with uuid 2902.


  1. Enable indications by writing '0200' at that handle using

    gatttool -b 00:11:22:33:44:55 --sec-level=high --char-write --handle=0xYYYY --value=0200

Where 0xYYYY is the handle of the CCCD descriptor that you noted in step 2. Once this happens, you should start getting indication data, which you can decipher using the temperature data structure found here.

If your device does not use the adopted thermometer profile, then you need to repeat the above three steps, but at step 1, instead of looking for a characteristic with uuid 2a1c, look for a characteristic which has 'char properties = 0x20' as this means that the characteristic can be indicatable.

You can find more information about using the BlueZ commands at the following links:-

  • How can I connect to the FitBit Zip over Bluetooth 4.0 LE on Linux with bluez?
  • Bluetooth Low Energy: listening for notifications/indications in linux
  • Using Bluetooth low energy in linux command line

I hope this helps.



Related Topics



Leave a reply



Submit