--- title: 樹莓派與藍芽低功耗(BLE) description: Raspberry Pi 3內建支持藍牙低功耗(BLE) # image: https://hackmd.io/screenshot.png tags: Raspberry Pi,Bluetooth # robots: noindex, nofollow langs: zh-Hant --- # 樹莓派與藍芽低功耗(BLE) ## 基本安裝檢查 Raspberry Pi 3內建支持藍牙低功耗(BLE)。 BLE是許多健身追踪器和智能手錶背後的技術,允許小型低功耗設備從中央計算機或智能手機傳輸和接收訊息。 > Raspberry Pi 3 B+ 支援 Bluetooth 4.2 > 傳輸速率 24 Mbit/s 最遠50公尺 Pi 3的內置藍牙適配器(adapter)稱為`hci0`。可以在終端使用以下命令檢查它是否正常運行: ```shell $ hciconfig ``` 終端應該顯示如下: ```shell $ hciconfig hci0: Type: Primary Bus: UART BD Address: B8:27:EB:43:5E:5A ACL MTU: 1021:8 SCO MTU: 64:1 UP RUNNING RX bytes:813 acl:0 sco:0 events:53 errors:0 TX bytes:2524 acl:0 sco:0 commands:53 errors:0 ``` 如果由於某種原因它顯示為DOWN,可以使用以下命令重新啟用它: ```shell $ sudo hciconfig hci0 up ``` ## BlueZ 樹莓派Raspbian使用的官方藍芽套件為 **[BlueZ]**,預設為5.43版,目標是更新到5.50版。 1. 首先使用`bluetoothctl -v`指令檢查BlueZ版本: ```shell $ bluetoothctl -v 5.43 ``` 2. 接下來是安裝依賴套件,先更新套件清單再依照下列指令進行安裝: ```shell $ sudo apt-get update $ sudo apt-get install libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev -y ``` 3. 下載BlueZ原始碼 ```shell $ wget www.kernel.org/pub/linux/bluetooth/bluez-5.50.tar.xz ``` 4. 解壓縮bluez-5.50.tar.xz ```shell $ tar xvf bluez-5.50.tar.xz && cd bluez-5.50 ``` 5. 進行編譯前配置 ```shell $ ./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var --enable-experimental ``` 6. 編譯BlueZ原始碼 ```shell $ make -j4 ``` 7. 安裝編譯完的BlueZ ```shell $ sudo make install ``` 8. 重新啟動樹莓派 ```shell $ sudo reboot ``` 9. 驗證是否已更新到BlueZ 5.50版 ```shell $ bluetoothctl -v bluetoothctl: 5.50 ``` ## References [1] [RPi Bluetooth LE - eLinux.org](https://elinux.org/RPi_Bluetooth_LE) [2] [Updating BlueZ on Raspberry Pi (from 5.43 to 5.50)](https://scribles.net/updating-bluez-on-raspberry-pi-from-5-43-to-5-50/) [BlueZ]: http://www.bluez.org/
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up