Gatttool Non-Interactive Mode --Char-Write

Gatttool Non-Interactive mode, multiple char-write-req

Found the solution on http://www.humbug.in/2014/using-gatttool-manualnon-interactive-mode-read-ble-devices/

gatttool -t random -i hci0 -b XX:XX:XX:XX:XX:XX --char-write-req --handle=0x001a  --value=0100; sleep 1; gatttool -t random -i hci0 -b XX:XX:XX:XX:XX:XX --char-write-req --handle=0x000f  --value=0100 --listen

Does the trick!

How to use gatttool non-interactive mode

the option is not --char-write but a --char-write-req.

Total command must be:

sudo gatttool -i hci0 -b 78:A5:04:44:0A:57 --char-write-req -a 0x0025 -n ff

BLE gatttool interactive shell script

If gattool writes prompts to stdout (and doesn't suppress them given non-TTY file descriptors), consider something like:

#!/usr/bin/env bash
case $BASH_VERSION in ''|[123].*|4.0.*) echo "ERROR: bash 4.1 or newer required" >&2; exit 1;; esac

exec {output_fd}>output.txt

prompt_re='[>] '
capture_re='^handle:.*value:.*$'

wait_for_prompt() {
IFS= read -r line || return
while ! [[ $line =~ $prompt_re ]]; do
[[ $line =~ $capture_re ]] && printf '%s\n' "$line" >&$output_fd
IFS= read -r line || return
done
}

wait_for_prompt
echo connect
while wait_for_prompt; do
echo "char-read-uuid 2d30c082-f39f-4ce6-923f-3484ea480596"
done

...saved as yourscript, and invoked using socat as:

socat 'SYSTEM:sudo gatttool -t random -b FF:3C:8F:22:C9:C8 -I 2>&1' 'EXEC:./yourscript'

(assuming that sudo is configured to work without a TTY; otherwise, you might move it to be sudo socat).

GATTTool fails to read/write 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.



Related Topics



Leave a reply



Submit