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.
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.
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 .
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With