我需要找到在我的蓝牙调制解调器范围内的可见蓝牙设备列表,以及它们各自的详细信息。我只需要处理蓝牙2.0及以下版本,不需要处理蓝牙4.0。
就像在Android手机上使用“搜索设备”一样。
很抱歉我没法提供我尝试过的代码,因为我不知道如何用Python处理蓝牙。
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)
另请参阅使用Python编程蓝牙
重要的是可以使用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
import bluetooth
nearby_devices = bluetooth.discover_devices()