Using gatttool in a manual/non-interactive mode to read BLE devices

Gatttool is a tool distributed along with Bluez, the default linux bluetooth stack, to interact with Bluetooth Low Energy (BLE) devices. Currently I have a TI SensorTag with me for a project I’m working on and I’m playing around with it. Most of the examples on the internet which show how to use gatttool to read the TI Tag have shown how to use gatttool in its interactive mode (-I). For eg, to read the temperature sensor, you’d do the following using gatttool’s interactive mode

@~ $ sudo gatttool -b BC:6A:29:AE:CC:23 -I
[   ][BC:6A:29:AE:CC:23][LE]> connect
[CON][BC:6A:29:AE:CC:23][LE]> char-read-hnd 0x25
[CON][BC:6A:29:AE:CC:23][LE]> 
Characteristic value/descriptor: 00 00 00 00 
[CON][BC:6A:29:AE:CC:23][LE]> char-write-cmd 0x29 01
[CON][BC:6A:29:AE:CC:23][LE]> char-read-hnd 0x25
[CON][BC:6A:29:AE:CC:23][LE]> 
Characteristic value/descriptor: f0 fe 88 0e 
[CON][BC:6A:29:AE:CC:23][LE]> exit

However gatttool also offers a non-interactive mode which hasn’t been documented. To achieve the above result in manual, non-interactive mode, you would do the following;

@$ sudo hciconfig hci0 down; sudo hciconfig hci0 up
@$ sudo gatttool -b BC:6A:29:AE:CC:23 --char-read -a 0x25; sleep 1; sudo gatttool -b BC:6A:29:AE:CC:23 --char-write -a 0x29 -n 01; sleep 1; sudo gatttool -b BC:6A:29:AE:CC:23 --char-read -a 0x25; 
Characteristic value/descriptor: 00 00 00 00 
Characteristic value/descriptor: 36 ff 68 0e

About Pratik Sinha

Linux Nerd, Socialist, Atheist, Adventuristic, Nature Lover, Geeky.

Leave a Reply

Your email address will not be published. Required fields are marked *