4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LinuxのGattToolとExpectを使ってNotificationを受け取るような処理をBashで書く

Last updated at Posted at 2016-04-24

小技。

gatttoolでNotificationを受け取るには-Iを使ってインタラクティブモードにする方法があるのですが、
それだと普通なら人間をコマンドを打ち込まないといけない気になります。

ただLinuxのexpectというコマンドを使うことで、期待する標準出力が流れるごとにコマンドを打ち込むという方法が可能です。

#!/bin/bash

expect <<EOF

spawn gatttool -b AA:BB:CC:DD:EE:FF -I
send "connect\n"
expect "Connection successful"
send "char-write-cmd 0x000a 0100\n"
send "char-write-cmd 0x000b AA\n"
expect "<任意の文字>"
disconnect

EOF

これでやろうと思えばなんでも出来そうです。

※ただこれをやるくらいならnobleを使った方が良い

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?