2014-01-08 194 views
1

我需要在我的藍牙調制解調器的範圍內找到可用藍牙設備的列表及其各自的詳細信息。我只需要做藍牙2.0及以下。我不需要做藍牙4.0。如何在Python中查找可見的藍牙設備?

就像你在使用「搜索設備」的Android手機上做的一樣。

對不起,我不能給任何代碼我試過,因爲我不知道如何用python做藍牙。

+0

是你想要什麼平臺來做到這一點呢? Android的? Linux呢?還有別的嗎? –

+0

@CharlieKilian我希望能夠在Linux和Windows上做到這一點。 – Ufoguy

回答

6

PyBluez鏈接herehere

from bluetooth import * 

print "performing inquiry..." 

nearby_devices = discover_devices(lookup_names = True) 

print "found %d devices" % len(nearby_devices) 

for name, addr in nearby_devices: 
    print " %s - %s" % (addr, name) 

另一個很好的鏈接here

的importent的事情是,你可以使用lookup_names = True

從bluez的文檔:

if lookup_names is False, returns a list of bluetooth addresses. 
if lookup_names is True, returns a list of (address, name) tuples 

這對蟒蛇2.6 ...如果你想爲2.7,你可以找到它here

2

您可以使用PyBluez:

import bluetooth 

nearby_devices = bluetooth.discover_devices() 
+0

你可以發佈它給出的輸出的例子嗎? – Ufoguy