I’ve been struggling for a few days reading and writing properties with gatttool on Linux. First of all, here is a description of my environment :
Host is linux PC with Ubuntu, also tested on embedded Linux on ARM
Device is MDEK1001
Here is the output when communicating on serial console :
[000017.440 INF] sys: fw2 fw_ver=x01030001 cfg_ver=x00010700
[000017.440 INF] uwb0: panid=xFA9F addr=xDECAF9944C021DAE
[000017.450 INF] mode: an (pasv,-)
[000017.450 INF] uwbmac: disconnected
[000017.450 INF] uwbmac: bh disconnected
[000017.460 INF] cfg: sync=0 fwup=0 ble=1 leds=1 init=0 upd_rate_stat=120 label=DW1DAE
[000017.460 INF] enc: off
[000017.470 INF] ble: addr=F9:57:64:6E:D5:3C
So if I’m correct, the firmware is the most up-to-date one.
Now, according to the documentation, it is possible to communicate over BLE using the GATT protocol, so using gatttool should be working. However, there are some properties I can read (e.g. Operation Mode, Device Info), but I can’t write anything. When I try, gatttool hangs forever, the blue LED remains ON, and I have to kill the application to end it. Maybe I do something wrong, are there some working examples of writing properties ?
On the other hand, the property I’m interesed in is the Persisted Position, in Anchor mode. The documentation specifies that it is write-only, but doing some tests with the Android application on 2 phones, it seems that is can also be read. During all my tests, it happened once that I could read the actual stored value (which was the right one), but it never occured again. Is there something to be done to read/write this property ?
Could you clarify what exactly you are trying to write and what version of Bluez you are using? Note that Bluez 4 has some known (but badly documented) issues when using LE devices.
Also note that the BLE API is only designed to work with the LEAPS app, so there are some weird quirks. One of these quirks is that the device auto-disconnects after a couple of seconds of BLE inactivity. It could be the device disconnects before you are able to read/write the characteristics you are interested in. I suggest subscribing to notifications as soon as youare connected to prevent disconnects.
You are right, this property seems to be read/write. I think this might be a mistake in the documentation.
Hi @seppe, and thanks a lot for this very helpful answer
Ok, I will definitely try it !
BlueZ version 5.48 on PC and 5.50 on embedded board. Not the most recent, but quite.
The property I want to write is the Persisted Position : we have a mapping application where the anchors are positionned buy a user, and then the application should setup the anchors via BLE. Then I will also have to set the Operation Mode to have an Initiator Anchor.
This actually seems to match with what I have seen. I will try the subscribing quirk.
I have played some time with the script, and the results are quite similar as when using gatttool directly : reading characteristics works well, except some of them, however writing Persistent Location does work via pygatt. So, after some deeper investigation, here are my conclusions :
The Android application does NOT use the Persistent Location attribute to display the location : it is retrieved using the Location Data => this actually confirms what the documentation says : the Persistent Location is Write Only and can’t be read.
The proper way to write the Persistent Location using gatttool is using --char-write-req instead of --char-write :
gatttool -b F9:57:64:6E:D5:3C --char-write-req -a 0x0016 -n 20000000000000000000000000
Now I should be able to integrate it into my application… Thanks again !!
Hi, I have used two platforms to connects to the tags : PC/Ubuntu and embedded ARM board/custom linux. I have not experienced connections losses, however I used to do only very small sessions : connect to the board, write the configuration, disconnect. Maybe you don’t have the same use case ?