Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GATTTool fails to read/write characteristics

I'm trying to use bluez's gatttool to write to some demo characteristics on a BLE custom board. Specifically I'm hoping to write to a characteristic and read the value back out. Here's what I'm doing (where 0x25 is the handle for the characteristic):

bluepy$ gatttool -b EC:24:B8:23:1C:39 -I
[   ][EC:24:B8:23:1C:39][LE]> connect
[CON][EC:24:B8:23:1C:39][LE]> char-read-hnd 0x0025 
[CON][EC:24:B8:23:1C:39][LE]> Characteristic value/descriptor: 01
[CON][EC:24:B8:23:1C:39][LE]> char-write-cmd 0x25 0x02
[CON][EC:24:B8:23:1C:39][LE]> char-read-hnd 0x0025
[CON][EC:24:B8:23:1C:39][LE]> Characteristic value/descriptor: 00

Does anyone know why the characteristic value read is 00 rather than 02 (second argument of char-write-cmd)?

Any help will be appreciated.

like image 835
WKleinberg Avatar asked Dec 20 '15 10:12

WKleinberg


People also ask

What is characteristic UUID?

The Characteristic UUID field is a 16-bit Bluetooth UUID or 128-bit UUID that describes the type of Characteristic Value. A client shall support the use of both 16-bit and 128-bit Characteristic UUIDs. A client may ignore any characteristic definition with an unknown Characteristic UUID.

What is a GATT characteristic?

A GATT characteristic is a basic data element used to construct a GATT service, BluetoothGattService . The characteristic contains a value as well as additional information and optional GATT descriptors, BluetoothGattDescriptor .

What is GATT profile in Bluetooth?

GATT is an acronym for the Generic ATTribute Profile, and it defines the way that two Bluetooth Low Energy devices transfer data back and forth using concepts called Services and Characteristics.


2 Answers

While there are rules and standards for BLE, the underlying device can simply ignore those and do their own thing. So, it's possible that it's listing the attribute as read-write and appearing to accept new values, but then just dropping the values. It shouldn't be doing that, but there's no reason it can't.

However, you should make sure that it's actually sending the right data and the issue is with the device... As mentioned in the comments gatttool can be a little messed up with interpreting inputs (newer versions are better than older ones), so try 02 or 2 instead of 0x02. You could also try using btmon to check that gatttool is actually sending the value you're intending.

like image 83
Tim Tisdall Avatar answered Sep 28 '22 10:09

Tim Tisdall


Check if some other software is not accessing Bluetooth.

I had similar issue when trying to read characteristics and node-red was also accessing same device. gatttool connected to the device but could not communicate with read / write. As soon as I stopped node-red it started to work.

like image 34
Uros Mesaric Avatar answered Sep 28 '22 09:09

Uros Mesaric