LoginSignup
4
1

More than 3 years have passed since last update.

Raspberry piでBluetoothテザリングを使う

Last updated at Posted at 2021-01-18

内容

タイトルの通り,Bluetooth PANができるようにRaspberry piと携帯電話を接続する。
他の方の記事を参考にして実行した際出たエラーに自分が行った解決を書く。

環境

  • iOS
  • Raspberry pi 4 Model B
    • Ubuntu desktop (20.04)

作業内容

この記事を参考にして行った。

Bluetoothが有効であることの確認

特に詰まるところはなかった。

必要なパッケージのインストール

sudo apt install curl wget python-dbus pulseaudio-module-bluetooth

とあるのだが,

$ sudo apt update
$ sudo apt install curl wget python-dbus pulseaudio-module-bluetooth
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
パッケージ python-dbus は使用できませんが、別のパッケージから参照されます。
これは、パッケージが欠落しているか、廃止されたか、または別のソース
からのみ利用可能であることを意味します。

E: パッケージ 'python-dbus' にはインストール候補がありません

上のように,python-dbusがない。

$ apt search python-dbus
ソート中... 完了
全文検索... 完了  
python-dbus-dev/groovy 1.2.16-3 all
  main loop integration development files for python3-dbus

python-dbus-doc/groovy 1.2.16-3 all
  Documentation for the D-Bus Python interface

python3-dbusmock/groovy 0.19-1 all
  mock D-Bus objects for tests

どうやらpython3-dbusがあるようなので,python-dbusはpython2が終わると共に廃止されてしまったのだろうか。

$ apt search python3-dbus
ソート中... 完了
全文検索... 完了  
python-dbus-dev/groovy 1.2.16-3 all
  main loop integration development files for python3-dbus

python-dbus-doc/groovy 1.2.16-3 all
  Documentation for the D-Bus Python interface

python3-dbus/groovy,now 1.2.16-3 arm64 [インストール済み、自動]
  simple interprocess messaging system (Python 3 interface)

---以下略---

python3-dbusを調べてみると,インストール済みらしい。(もし違ったらsudo apt install python3-dbusすれば良いと思う)
なので,先ほどのものからpython-dbusを抜いて実行。

sudo apt install curl wget pulseaudio-module-bluetooth

インストールができた。

bt-panをダウンロードし(これはpython2のスクリプト)実行権限を付与,/usr/bin/ 下に移動する(元の記事通り)。

wget https://raw.githubusercontent.com/mk-fg/fgtk/master/bt-pan
chmod +x bt-pan
sudo chown root: bt-pan
sudo mv bt-pan /usr/bin/

スマートフォン側の設定

bluetoothctlを使ってペアリング

先程と同じ記事を参照

bt-panでPAN接続

詰まった。

結論から言うと,bt-panの先頭の#!/usr/bin/env python2のpython2をpython3に書き換えて,sudo 2to3-2.7 -w /usr/bin/bt-panした。

頭が悪い解決ではあるが,動作させることができた。
もっと良い方法があるはずなので,もし見つけた方がいらっしゃったら教えてくださると嬉しく思う。

あとは元の記事通りに行い,ubuntuのネットワーク設定からインターネット共有に接続すればよい。(これってもしかして元からできたりする?もしそうだったら泣く)


有益であろう情報は以上だが,一応下に顛末を書いておく。

$ sudo bt-pan client アドレス
/usr/bin/env: ‘python2’: No such file or directory

仕方がないのでpython2をインストール。

$ sudo apt install python2
$ sudo bt-pan client アドレス
Traceback (most recent call last):
  File "/usr/bin/bt-pan", line 6, in <module>
    import dbus
ImportError: No module named dbus

それはそう。

前の手順で確認したpython3-dbusはpython3のためのもので,bt-panが依存しているのはpython-dbusなので当然。

pipをインストールし,pipからpython-dbusが入れられないか確かめた。
しかしエラーを吐いたので,いっそpython3で実行できないものかと思ったらうまく行ってしまった。

bt-panが何もエラーや途中経過を吐かなくて不安だったが, debugオプションを付ければ処理が進行しているのを知ることができる。


参考にしたもの

スマホからRaspberry PiをBluetooth経由で操作 - Qiita
https://qiita.com/c60evaporator/items/114c4fe6fab042da1b25 (最終閲覧日:2020年1月18日)

2to3 - Python 2 から 3 への自動コード変換 — Python 3.9.1 ドキュメント
https://docs.python.org/ja/3/library/2to3.html (最終閲覧日:2020年1月18日)

4
1
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
1