Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

Raspberry PiとWindows10をBluetoothで通信する その1:文字列の送受信

実際のところ

bluetoothctlコマンドをたたくと、対話形式のウィザードがでます

$ sudo bluetoothctl
Agent registered
[bluetooth]# 

電源ON

[bluetooth]# power on
Changing power on succeeded

検索可能に

[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller B8:27:EB:4E:F6:C9 Discoverable: yes

この状態で、WindowsBluetoothバイス追加から、RaspberryPiがいれば成功
f:id:shuzo_kino:20201230002021p:plain

接続
f:id:shuzo_kino:20201230002314p:plain

無事うまくいくと、こんな感じで出るはず

[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller B8:27:EB:4E:F6:C9 Discoverable: yes
[NEW] Device 98:AF:65:2C:BA:8B DESKTOP-F902L8T
[CHG] Device 98:AF:65:2C:BA:8B UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 98:AF:65:2C:BA:8B UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 98:AF:65:2C:BA:8B Modalias: bluetooth:v0006p0001d0A00
[CHG] Device 98:AF:65:2C:BA:8B UUIDs: 00001000-0000-1000-8000-00805f9b34fb
[CHG] Device 98:AF:65:2C:BA:8B UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device 98:AF:65:2C:BA:8B UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 98:AF:65:2C:BA:8B UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 98:AF:65:2C:BA:8B UUIDs: 00001115-0000-1000-8000-00805f9b34fb
[CHG] Device 98:AF:65:2C:BA:8B UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device 98:AF:65:2C:BA:8B UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device 98:AF:65:2C:BA:8B UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device 98:AF:65:2C:BA:8B UUIDs: c7f94713-891e-496a-a0e7-983a0946126e
[CHG] Device 98:AF:65:2C:BA:8B ServicesResolved: yes
[CHG] Device 98:AF:65:2C:BA:8B Paired: yes
[CHG] Device 98:AF:65:2C:BA:8B ServicesResolved: no
[CHG] Device 98:AF:65:2C:BA:8B Connected: no

"/etc/systemd/system/dbus-org.bluez.service"を編集

[Unit]
Description=Bluetooth service
Documentation=man:bluetoothd(8)
ConditionPathIsDirectory=/sys/class/bluetooth

[Service]
Type=dbus
BusName=org.bluez
ExecStart=/usr/lib/bluetooth/bluetoothd
...

[Unit]
Description=Bluetooth service
Documentation=man:bluetoothd(8)
ConditionPathIsDirectory=/sys/class/bluetooth

[Service]
Type=dbus
BusName=org.bluez
ExecStart=/usr/lib/bluetooth/bluetoothd
...
$ sudo systemctl daemon-reload
$ sudo systemctl restart bluetooth

sdpに権限

$ sudo chmod 777 /var/run/sdp

ポートを設定

$ sudo sdptool add --channel=22 SP
Serial Port service registered

ポートを受信状態に

$ sudo rfcomm listen /dev/rfcomm0 22
Waiting for connection on channel 22
Connection from 98:AF:65:2C:BA:8B to /dev/rfcomm0
Press CTRL-C for hangup

ふたたびWindows側の用意

コントロールパネルから
f:id:shuzo_kino:20201230004634p:plain

RaspberryPiのプロパティを選択
f:id:shuzo_kino:20201230004825p:plain
サービスのタブから、SPPをチェック
f:id:shuzo_kino:20201230004925p:plain
COM番号が割り当てられました
f:id:shuzo_kino:20201230005032p:plain

TeraTermで接続
f:id:shuzo_kino:20201230005158p:plain


f:id:shuzo_kino:20201230010558p:plain

/var/run/sdpなんてフォルダがないが?

bluetoothの設定を反映し、リロードしないとデフォでは存在しません。