RaspberryPi同士でbluetooth通信した
タイトルどおり,ラズパイ同士で情報のやりとりをしたく, bluetooth通信を行いました.
基本的には,以下の記事通りにやれば動きます.
いくつか引っかかる点があったので,メモっておきます.
sudoで実行しよう
bluetoothctl
を動かすとき,sudoで実行しないとペアリングなどのコマンドを受け付けてくれなかったです.
$ sudo bluetoothctl [bluetooth]#
Failed to pair: org.bluez.Error.AuthenticationFailed
hciconfig
を使って,ペアリングの実験をおこなう際に以下のようなエラーが発生しました.
(server)$ sudo bluetoothctl [bluetooth]# discoverable on Changing discoverable on succeeded [CHG] Controller SERVER_ADDR Discoverable: yes
(client)$ sudo bluetoothctl [bluetooth]# pair SERVER_ADDR Attempting to pair with SERVER_ADDR Failed to pair: org.bluez.Error.AuthenticationFailed
解決策は以下のサイトで見つけました.
結局,client側のbluetoothデバイスはoffになっていただけでした.
僕の環境では以下のようにしたら動くようになりました.
(client)$ sudo bluetoothctl [bluetooth]# power on Changing power on succeeded [CHG] Controller CLIENT_ADDR Powered: yes [bluetooth]# pair SERVER_ADDR Attempting to pair with SERVER_ADDR [CHG] Device SERVER_ADDR Connected: yes [CHG] Device SERVER_ADDR Paired: yes Pairing successful
Bluetoothの自動起動設定
「電源切れてました٩( ᐛ )و」なんて,アホっぽい間違いを犯さないように, 自動で電源が入るように設定しておきます.
/etc/bluetooth/main.conf
に以下を追記.
[Policy] AutoEnable=true
/etc/systemd/system/bluetooth.service.d/policy.conf
に以下を追記.
[Service] ExecStart= ExecStart=/usr/lib/bluetooth/bluetoothd --plugin=policy