最近研究Ibeacon用到树莓派上扫描Ibeacon基站的问题.使用python的话需要用到bulez. 安装过程及遇到的问题的解决办法如下:
一、在树莓派3上安装BlueZ
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install libusb-dev
sudo apt-get install libglib2.0-dev --fix-missing
sudo apt-get install libudev-dev
sudo apt-get install libical-dev
sudo apt-get install libreadline-dev
sudo apt-get install libdbus-glib-1-dev
sudo apt-get install bluetooth bluez blueman
sudo apt-get install python-bluez
注意:我是在树莓派官方系统版本2019-04-08-raspbian-stretch下,直接执行下面的标色代码,就解决问题了
安装libbluetooth-dev
sudo apt-get install libbluetooth-dev
安装pybluez
sudo pip install pybluez
直到看到Successfully installed pybluez,安装成功
pybluez 查询蓝牙
官方的示例inquiry.py
import bluetooth
print("performing inquiry...")
nearby_devices = bluetooth.discover_devices(lookup_names = True)
print("found %d devices" % len(nearby_devices))
for addr, name in nearby_devices:
print(" %s - %s" % (addr, name))
树莓派自带blueZ进行升级
通过命令bluetoothctl -v查看可知,209年4月版的树莓派3系统上的blueZ是5.43的版本,还有更新的版本,后面的bluetoothctl命令很多都没有,所以我进行重新安装,将它升级成了5.49的版本。
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install -y libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev
以上都是准备工作
sudo wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.49.tar.xz
sudo tar xf bluez-5.49.tar.xz
cd bluez-5.49/
sudo ./configure
sudo make
sudo make install
重启树莓派
sudo reboot
# check version
bluetoothctl -v
显示系统BlueZ版本已经到5.49了
sudo vim /lib/systemd/system/bluetooth.service
# Add --experimental to this lane
ExecStart=/usr/local/libexec/bluetooth/bluetoothd --experimental
sudo systemctl daemon-reload
sudo systemctl restart bluetooth
sudo hciconfig hci0 up
sudo reboot
sudo usermod -G bluetooth -a pi
sudo reboot
还不快抢沙发