bluetooth.service を起動
sudo systemctl enable bluetooth.service
sudo systemctl start bluetooth.service
% sudo hcitool lescan
...
48:27:E2:83:C5:F2 BLECTF
gatttool -b (MACアドレス) --char-read -a (handle)
# ASCIIのデコード付き
gatttool -b (MACアドレス) --char-read -a (handle) |awk -F':' '{print $2}' |tr -d ' '|xxd -r -p;printf '\\n'
# 例
gatttool -b 48:27:E2:83:C5:F2 --char-read -a 0x002a |awk -F':' '{print $2}' |tr -d ' ' |xxd -r -p; printf '\\n'
gatttool -b (MACアドレス) --char-write-req -a (handle) -n (書き込む値hex)
# 例
gatttool -b 48:27:E2:83:C5:F2 --char-write-req -a 0x002c -n $(echo -n "some value"|xxd -ps)
notifyを受け取るには、適切なハンドルに 0100
を書き込む。Listenするため、gatttoolをインタラクティブモードで使う。
% gatttool -I -b 48:27:E2:83:C5:F2
[48:27:E2:83:C5:F2][LE]> connect
Attempting to connect to 48:27:E2:83:C5:F2
Connection successful
[48:27:E2:83:C5:F2][LE]> char-write-req 0040 0100
Characteristic value was written successfully
Notification handle = 0x0040 value: 35 65 63 33 37 37 32 62 63 64 30 30 63 66 30 36 64 38 65 62
indicationを受け取るには、適切なハンドルに 0200
を書き込む。受信し、ackを返すため、gatttoolをインタラクティブモードで使う。
% gatttool -I -b 48:27:E2:83:C5:F2
[48:27:E2:83:C5:F2][LE]> connect
Attempting to connect to 48:27:E2:83:C5:F2
Connection successful
[48:27:E2:83:C5:F2][LE]> char-write-req 0044 0200
Characteristic value was written successfully
Indication handle = 0x0044 value: 63 37 62 38 36 64 64 31 32 31 38 34 38 63 37 37 63 31 31 33Notification handle = 0x0040 value: 35 65 63 33 37 37 32 62 63 64 30 30 63 66 30 36 64 38 65 62