低功耗蓝牙(BLE)有时不能被传统的一些方式搜索到,所以这里我们给出一种可以搜索到BLE的代码,给大家参考
from bluetooth import *
from bleak import BleakScanner, BleakClient
import asyncio
bluetoothlist=[]
async def get_bluetoothlist():
global bluetoothlist
devices = await BleakScanner.discover()
for d in devices:
bluetoothlist.append((d.name, d.address))
asyncio.run(get_bluetoothlist())
# 得到bluetoothlist,里面每一个都是一个元组(name,address)