2016-05-31 72 views
0

我得到了下面的代码:Python的蓝牙没有返回值(树莓PI)

import bluetooth 


def apparaat(): 
    nearby_devices = bluetooth.discover_devices(lookup_names = True, flush_cache = True, duration = 15) 
    for address in nearby_devices: 
     print("Gevonden apparaten: " + str(address)) 
    print("Gevonden apparaten: " + str(nearby_devices)) 
apparaat() 

当我运行该脚本的出来说就是:

Gevonden apparaten: [] 

当我扫描我的覆盆子蓝牙设备PI会返回一对夫妇。什么我在这里失踪?

+0

是否安装PI-蓝牙? sudo apt-get install pi-bluetooth – Lazykiddy

+0

是的,我做了:(!(感谢您的帮助) – joey

+0

当你的蓝牙设备返回时,你如何扫描蓝牙设备? – Lazykiddy

回答

1

你可以试着运行这段代码吗?我发现有人将这个蓝牙包从Python 2.7移植到3.x,并且在打印unicode字符串时可能引入了一些错误。

import bluetooth 
x = bluetooth.discover_devices() 
n = bluetooth.lookup_name(x[0]) 
print(n) 

(来源:https://groups.google.com/forum/#!topic/pybluez/Kq-ViMBo6es

+0

你好,谢谢你的答案,当我运行这段代码时,我得到以下错误: BluetoothError:与本地蓝牙适配器通信错误尝试明确它的含义 – joey

+0

重启后的蓝牙服务我得到的错误:没有这样的设备大声笑 – joey

+0

你不是在同一时间与其他软件一起使用吗? 提示:http://www.instructables.com/id/Raspberry-Pi-Bluetooth-InOut- Board-or-Whos-Hom /?ALLSTEPS 也许试试 “wget https://pybluez.googlecode.com/svn/trunk/examples/simple/inquiry.py python inquiry.py” – Lazykiddy