5

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.

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72
WKleinberg
  • 53
  • 1
  • 4
  • `gatttool` is very finicky. Try `char-write-cmd 0x25 02` instead (that is, without the `0x` in the value). – kaylum Dec 20 '15 at 22:27
  • 1
    I would avoid using `gatttool` as I have never had a good experience with it. Try `bluetoothctl` or `btgatt-client` instead and see if you find that working better for you. Also do note that descriptors are not the same as values. – Zimano Dec 21 '15 at 10:22
  • check if you have write permissions and also char-write-cmd doesnt have any response so better got for char-write-req ;if you dont have permissions it would prompt error – Jagdish Dec 21 '15 at 11:26
  • @kaylum You're right! Removing `0x` did it. Does that mean that the second parameter is assumed to be hex? – WKleinberg Dec 25 '15 at 17:30

2 Answers2

4

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.

Tim Tisdall
  • 9,914
  • 3
  • 52
  • 82
1

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.

Uros Mesaric
  • 311
  • 2
  • 5