树莓派 python bluetooth,用pybluez控制蓝牙

2019/08 29 18:08

安装pybluez

直接安装pybluez的时候报错了

  1. Infile included from bluez/btmodule.c:20:0:
  2. bluez/btmodule.h:5:33: fatal error: bluetooth/bluetooth.h: No such fileor directory

google后的结果是没有安装libbluetooth-dev

 

安装libbluetooth-dev

 sudo apt-get install libbluetooth-dev

安装pybluez

 sudo pip install pybluez

直到看到Successfully installed pybluez,安装成功

 

pybluez 查询蓝牙

官方的示例inquiry.py

  1. import bluetooth
  2. print("performing inquiry...")
  3. nearby_devices = bluetooth.discover_devices(lookup_names = True)
  4. print("found %d devices" % len(nearby_devices))
  5. for addr, name in nearby_devices:
  6. print(" %s - %s" % (addr, name))

查找了手机的蓝牙

  1. ⚙ ubuntu@ubuntu  ~  python findblue.py
  2. performing inquiry...
  3. found 1 devices
  4. 28:CF:E9:1C:42:2A - phodal

--转载请注明: http://91o.cc/%e6%a0%91%e8%8e%93%e6%b4%be-python-bluetooth%ef%bc%8c%e7%94%a8pybluez%e6%8e%a7%e5%88%b6%e8%93%9d%e7%89%99/