python bluetooth 选择特定蓝牙模块进行扫描
0X01
蓝牙分为低功耗蓝牙和经典蓝牙,但是同一个蓝牙模块不能同时扫描两种蓝牙信息,因此需要两个蓝牙模块来分别进行对两种蓝牙扫描。
网上查阅了以下蓝牙的信息,发现在linux 下,蓝牙模块使用0,1,2来标记蓝牙模块。
蓝牙python bluez模块中device_id 是使用指定蓝牙模块来工作的,默认是-1
#================Bluez internal methods============
def _gethcisock(device_id= -1):
try:
sock = _bt.hci_open_dev(device_id)
except:
raise BluetoothError("error accessing bluetooth device")
return sock
于是我使用device_id=1 来确定使用使用哪一个蓝牙模块(0是默认的,因此0 自动给没有分配id的蓝牙扫描使用)
print '-----------------经典蓝牙--------------------------------'
nearby_devices = bluetooth.discover_devices(lookup_names=
True, lookup_class=True,device_id=1)
print nearby_devices
print "scan end!"