Raspberry Pi 備忘録 / Mbedもあるよ!

Raspberry Pi であれこれやった事の記録

Bluetooth シリアル通信を試す

ペアリング

hcitool scan

必要なら bluez-test-device remove __MAC___

bluez-simple-agent hci0 MAC

# sdptool browse local | grep Serial
# sdptool add --channel=22 SP
Serial Port service registered
~# sdptool browse local | grep Serial
Service Name: Serial Port
  "Serial Port" (0x1101)
  "Serial Port" (0x1101)
# rfcomm listen /dev/rfcomm0 22
Waiting for connection on channel 22

アンドロイドから、 insercureで接続する。

なかなか安定しないが、 root の xwindow で GUI Blueman で、シリアルポート > Bluetoothinsecure を選んで、Android側でも接続すると、成功しやすい気がする。
接続すると、

Connection from 1C:7B:21:4C:14:89 to /dev/rfcomm0
Press CTRL-C for hangup

と出る。

ここで、 Ctrl + z > bg で、バックグラウンドジョブに移行して欲しいのだが、すんなりは行かない。
Ctrl + z しても、一見、バックグラウンドジョブに成っていないように見えるのだ。
だが、Ctrl + z して、 Ctrl + c して、

# ps axuw | grep listen
root      2840  0.9  1.6  27448 14252 tty8     S<s+ 11:31   0:09 /usr/bin/X -nolisten tcp :0 -auth /tmp/serverauth.nBMuCLbMfG

と、ちゃんと走っているのが分かる。

$ cat /dev/rfcomm0
$ echo "hello" > /dev/rfcomm0

で、動作確認する。

切断

# kill %1

トラブル対処

# rfcomm release 0
Can't release device: Operation already in progress

プロセスが残っていたので、 kill した。