たれぱんのびぼーろく

わたしの備忘録、生物学とプログラミングが多いかも

Raspberry Pi Zero WをBluetooth経由で操作する

sshみたいなノリで、Bluetooth経由のRPiリモートアクセスを可能にする。

概要

Bluetooth上でシリアル通信をおこない、シリアル通信のRaspberry Pi側終端をagettyにつなぐことでリモートアクセスを可能にする。
BluetoothdのUnitを少しいじり、rfcomm->agettyのdaemon用Unitをかけば、立ち上げ時に自動で受け入れ態勢をONにできる。

登場人物

  • SPP (Serial Port Profile): Serial通信を可能にするBluetoothプロファイル。
  • SDP (Service Discovery Protocol): 使用可能プロファイルを通知するBluetoothプロファイル。
  • RFCOMM : SPPに関連したBluetoothプロファイル。

以下の二つを読めば0から設定できる、すごい。なので本稿では全体像と仕組みを示そうと思う。 Bluetoothを介した Windows <-> RPi シリアル通信 Raspberry Pi 2にBluetoothシリアル通信でデータ送受信してみた - カタカタブログ
シリアル通信に乗っかったRPiログイン Raspberry Pi 3にBluetoothでログインする - Qiita

シリアル通信からログインまで

rfcomm [ options ] < command > < dev >

Options
-r
Switch TTY into raw mode (doesn't work with "bind").

Commands
watch [channel] [cmd]
Listen on a specified RFCOMM channel for incoming connections.
If cmd is given, it will be executed as soon as a client connects.

sudo rfcomm -r watch 0 22 /sbin/agetty -L rfcomm0 115200 & 管理者権限において、rfcomm channel #x をwatchし、接続確立後ただちにボーレート115200にてログイン処理を行え

Man page of AGETTY
rfcomm(1): RFCOMM config utility - Linux man page