环境
树莓派3b+
python3.7
蓝牙设备
pybluez库
github链接:https://github.com/pybluez/pybluez
- 安装库
sudo pip3 install pybluez
- 简单扫描
import bluetooth
nearby_devices = bluetooth.discover_devices(lookup_names=True)
print("Found {} devices.".format(len(nearby_devices)))
for addr, name in nearby_devices:
print(" {} - {}".format(addr, name))
能够正常运行,但只能扫描到手机。我用的是蓝牙卡片,手机扫描到的是在其他设备
栏里,查找资料发现是属于低功耗蓝牙设备ibeacon
。下面还有另一个官方示例,提示是扫描低功耗的,尝试一下。
- 低功耗扫描
from bluetooth.ble import DiscoveryService
service = DiscoveryService()
devices = service.discover(2)
for address, name in devices.items():
print("name: {}, address: {}".format(name, address))
运行后提示缺少gattlib
库