gatttool characteristic write in non-interactive mode

797 Views Asked by At

I want to use gatttool in a shell script.

What I want to achieve is similar to these:

In interactive mode I can do this:

# gatttool -b xx:xx:xx:xx:xx:xx -I
[xx:xx:xx:xx:xx:xx][LE]> connect
Attempting to connect to xx:xx:xx:xx:xx:xx
Connection successful
[xx:xx:xx:xx:xx:xx][LE]> char-write-cmd 0x0025 aabbcc
Notification handle = 0x0025 value: aa bb cc

Now if I run non-interactively:

# gatttool -b xx:xx:xx:xx:xx:xx --char-write --handle=0x0025 --value=aabbcc

It just hangs I need to break it with CTRL+C and does not send anything to the device.

Now, all questions above are recommending to use --char-write-req instead of --char-write.

But that it is misleading, as request and command mean different things.

My device does not accept request, only commands (even in interactive mode!). So trying to send the same data with request will fail:

# gatttool -b xx:xx:xx:xx:xx:xx -I
[xx:xx:xx:xx:xx:xx][LE]> connect
Attempting to connect to xx:xx:xx:xx:xx:xx
Connection successful
[xx:xx:xx:xx:xx:xx][LE]> char-write-req 0x0025 aabbcc
Error: Characteristic Write Request failed: Attribute can't be written

Now of course using the recommendations from the above questions (--char-write-req) will fail:

# gatttool -b xx:xx:xx:xx:xx:xx --char-write-req --handle=0x0025 --value=aabbcc
Characteristic Write Request failed: Attribute can't be written

So what is the non-interactive alternative of writing a characteristic command, If I don't want to use any Python or similar overkills for this?

0

There are 0 best solutions below