BLE
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[Python-Servo]]
* BLEを使った Raspberry Pi Zero <-> Raspberry Pi 4 <-> Ra...
** BLEのアドレス [#mba34e5d]
testpip) pi@rpi-202603261445:~/python $ hciconfig
hci0: Type: Primary Bus: UART
BD Address: B8:27:EB:ED:CD:2A ACL MTU: 1021:8 SCO MTU:...
UP RUNNING
RX bytes:6056 acl:128 sco:0 events:331 errors:0
TX bytes:37576 acl:118 sco:0 commands:259 errors:0
** [#x08b5382]
2. 動かない時のチェックリスト(重要)
プログラムを修正しても NoReply や接続エラーが出る場合、O...
1. Bluetoothサービスの権限
2. Raspberry PiでBlueZをユーザー権限から操作する場合、権...
3.
4. 既存のアドバタイズのクリア
5. 以前の実行情報が残っていると競合します。一度 Bluetoot...
6. sudo hciconfig hci0 up
7.
8. Bluetoothデーモンの設定 (Peripheral側)
9. bluez-peripheral を使う場合、Bluetoothを「Experimenta...
* /lib/systemd/system/bluetooth.service を開き、
* ExecStart=/usr/lib/bluetooth/bluetoothd の末尾に -E...
* その後 sudo systemctl daemon-reload && sudo system...
3. Central側 (Pi 4) のヒント
Central側の NoReply は、相手(Zero)が接続を承認した直後...
* Zero側の peripheral2.py を起動し、「Peripheral 準備完...
* もし Bleak で Service not found が出る場合は、一度 blu...
まずは 「双方 sudo で実行」 と 「Bluetoothサービスのリセ...
** sudo で実行していても、D-Bus側で拒否されることがありま...
- ファイルパス: bluetooth-python.conf (新規作成)
- 内容:
- XML
#code(XML){{
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus...
"http://www.freedesktop.org/standards/dbus/1.0/busconfig...
<busconfig>
<policy user="root">
<allow send_destination="org.bluez"/>
</policy>
<policy user="pi">
<allow send_destination="org.bluez"/>
</policy>
<policy context="default">
<allow send_destination="org.bluez"/>
</policy>
</busconfig>
}}
- ※作成後、sudo systemctl restart dbus を実行してください。
** 3. 最終手段の確認:Bluetoothの状態 [#jbb827d0]
hciconfig で UP になっていても、BlueZが管理を放棄している...
Bash
# 一旦リセットしてBlueZに再認識させる
sudo bluetoothctl power off
sudo bluetoothctl power on
sudo bluetoothctl scan on # 数秒動かして Ctrl+C
その上で、再度実行します:
Bash
sudo ./testpip/bin/python3 peripheral2.py
これで get_first で失敗しても、後半の「手動取得」の方で h...
$ sudo bluetoothctl power on
Failed to set power on: org.bluez.Error.Failed
このエラーはBluetoothのハードウェアブロック、ドライバの...
まず、ターミナルで rfkill unblock bluetooth を実行し、そ...
sudo rfkill unblock bluetooth
sudo systemctl restart bluetooth
sudo hciconfig hci0 down
sudo hciconfig hci0 up
- # ペアリング・エージェントを無効化(一時的)
sudo bluetoothctl agent off
- # 念のため信頼関係もリセット
sudo bluetoothctl untrust B8:27:EB:C7:CE:F9
** Raspberry PiでBLE On, Wifi Off にする方法 [#c2ebdb61]
- https://nosubject.io/raspberry-pi-os-how-do-i-turn-off...
** xxx [#a2866261]
sudo bluetoothctl remove <相手のMACアドレス>
sudo bluetoothctl remove B8:27:EB:C7:CE:F9
sudo bluetoothctl remove E4:5F:01:B1:D7:F2
sudo bluetoothctl remove B8:27:EB:ED:CD:2A
sudo bluetoothctl remove E4:5F:01:B1:D7:78
** 3. 【最重要】Bluetooth デーモンの完全リセット [#b6414f...
- これまでの「ゴミ」が OS のメモリに残っている可能性があ...
+ プログラムを止める (Ctrl+C)
+ キャッシュフォルダを消去する(これが一番効きます)
Bash
sudo rm -rf /var/lib/bluetooth/*
sudo systemctl restart bluetooth
+ Peripheral 側を起動
+ Central 側を起動
- なぜこれが必要か
-- 先ほどの remove 時のログを見ると、マイク制御やボリュー...
- これで NoReply エラーが消え、Discovering services... の...
** xxxxx [#a1cb6aa4]
sudo hciconfig hci0 up
sudo bluetoothctl power on
sudo systemctl stop bluetooth
sudo killall -9 bluetoothd 2>/dev/null
sudo systemctl start bluetooth
sudo bluetoothctl show
終了行:
[[Python-Servo]]
* BLEを使った Raspberry Pi Zero <-> Raspberry Pi 4 <-> Ra...
** BLEのアドレス [#mba34e5d]
testpip) pi@rpi-202603261445:~/python $ hciconfig
hci0: Type: Primary Bus: UART
BD Address: B8:27:EB:ED:CD:2A ACL MTU: 1021:8 SCO MTU:...
UP RUNNING
RX bytes:6056 acl:128 sco:0 events:331 errors:0
TX bytes:37576 acl:118 sco:0 commands:259 errors:0
** [#x08b5382]
2. 動かない時のチェックリスト(重要)
プログラムを修正しても NoReply や接続エラーが出る場合、O...
1. Bluetoothサービスの権限
2. Raspberry PiでBlueZをユーザー権限から操作する場合、権...
3.
4. 既存のアドバタイズのクリア
5. 以前の実行情報が残っていると競合します。一度 Bluetoot...
6. sudo hciconfig hci0 up
7.
8. Bluetoothデーモンの設定 (Peripheral側)
9. bluez-peripheral を使う場合、Bluetoothを「Experimenta...
* /lib/systemd/system/bluetooth.service を開き、
* ExecStart=/usr/lib/bluetooth/bluetoothd の末尾に -E...
* その後 sudo systemctl daemon-reload && sudo system...
3. Central側 (Pi 4) のヒント
Central側の NoReply は、相手(Zero)が接続を承認した直後...
* Zero側の peripheral2.py を起動し、「Peripheral 準備完...
* もし Bleak で Service not found が出る場合は、一度 blu...
まずは 「双方 sudo で実行」 と 「Bluetoothサービスのリセ...
** sudo で実行していても、D-Bus側で拒否されることがありま...
- ファイルパス: bluetooth-python.conf (新規作成)
- 内容:
- XML
#code(XML){{
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus...
"http://www.freedesktop.org/standards/dbus/1.0/busconfig...
<busconfig>
<policy user="root">
<allow send_destination="org.bluez"/>
</policy>
<policy user="pi">
<allow send_destination="org.bluez"/>
</policy>
<policy context="default">
<allow send_destination="org.bluez"/>
</policy>
</busconfig>
}}
- ※作成後、sudo systemctl restart dbus を実行してください。
** 3. 最終手段の確認:Bluetoothの状態 [#jbb827d0]
hciconfig で UP になっていても、BlueZが管理を放棄している...
Bash
# 一旦リセットしてBlueZに再認識させる
sudo bluetoothctl power off
sudo bluetoothctl power on
sudo bluetoothctl scan on # 数秒動かして Ctrl+C
その上で、再度実行します:
Bash
sudo ./testpip/bin/python3 peripheral2.py
これで get_first で失敗しても、後半の「手動取得」の方で h...
$ sudo bluetoothctl power on
Failed to set power on: org.bluez.Error.Failed
このエラーはBluetoothのハードウェアブロック、ドライバの...
まず、ターミナルで rfkill unblock bluetooth を実行し、そ...
sudo rfkill unblock bluetooth
sudo systemctl restart bluetooth
sudo hciconfig hci0 down
sudo hciconfig hci0 up
- # ペアリング・エージェントを無効化(一時的)
sudo bluetoothctl agent off
- # 念のため信頼関係もリセット
sudo bluetoothctl untrust B8:27:EB:C7:CE:F9
** Raspberry PiでBLE On, Wifi Off にする方法 [#c2ebdb61]
- https://nosubject.io/raspberry-pi-os-how-do-i-turn-off...
** xxx [#a2866261]
sudo bluetoothctl remove <相手のMACアドレス>
sudo bluetoothctl remove B8:27:EB:C7:CE:F9
sudo bluetoothctl remove E4:5F:01:B1:D7:F2
sudo bluetoothctl remove B8:27:EB:ED:CD:2A
sudo bluetoothctl remove E4:5F:01:B1:D7:78
** 3. 【最重要】Bluetooth デーモンの完全リセット [#b6414f...
- これまでの「ゴミ」が OS のメモリに残っている可能性があ...
+ プログラムを止める (Ctrl+C)
+ キャッシュフォルダを消去する(これが一番効きます)
Bash
sudo rm -rf /var/lib/bluetooth/*
sudo systemctl restart bluetooth
+ Peripheral 側を起動
+ Central 側を起動
- なぜこれが必要か
-- 先ほどの remove 時のログを見ると、マイク制御やボリュー...
- これで NoReply エラーが消え、Discovering services... の...
** xxxxx [#a1cb6aa4]
sudo hciconfig hci0 up
sudo bluetoothctl power on
sudo systemctl stop bluetooth
sudo killall -9 bluetoothd 2>/dev/null
sudo systemctl start bluetooth
sudo bluetoothctl show
ページ名: