🔵 BLE 蓝牙工具 · Bleak

Python 低功耗蓝牙扫描/连接/读写工具,已在 Windows 本机安装

📦 安装状态

Bleak 3.0.2 已安装

Python 3.12.9 · Windows 11 · 已通过 BLE 扫描验证

📡 最近一次扫描结果
2026-07-15 扫描 · 20 秒 · 发现 11 个设备
-50(未命名) 88:66:11:50:37:7A华米手环
-50(未命名) 02:43:72:FB:31:76未知
-58(未命名) C3:83:C1:68:7E:B8未知
-72(未命名) 79:6A:0B:7C:A3:82fdaa 服务
-78D06 ProD1:FF:F8:65:69:DF
-90U-EWH363A家电
信号值 RSSI (dB) · 越接近 0 信号越强
📋 能力清单
能力 状态 说明
扫描附近 BLE 设备 发现设备名称、地址、信号强度、广播服务 UUID
读取设备特征值 已成功读取华米手环数据
连接已配对设备 需先经 Windows 蓝牙配对后使用
未配对设备直连 ⚠️ 受限 BLE 隐私地址轮换太快,扫描到连接之间地址失效
订阅 notify 实时数据 待测试 需要已配对的 BLE 设备配合测试
🔧 快速参考

安装

pip install bleak

注:本机需设代理环境变量为空 HTTP_PROXY="" HTTPS_PROXY="" 绕过代理超时

扫描 30 秒

python -c "
import asyncio
from bleak import BleakScanner
async def scan():
    devices = {}
    def cb(d, ad):
        if d.address not in devices:
            devices[d.address] = (d.name or '(未命名)', ad.rssi if ad else -999)
            print(f'  [{ad.rssi:>4}] {d.name or chr(40)+chr(26410)+chr(21629)+chr(21517)+chr(41):<35} {d.address}')
    s = BleakScanner(detection_callback=cb)
    await s.start()
    await asyncio.sleep(30)
    await s.stop()
    print(f'\n发现 {len(devices)} 个设备')
asyncio.run(scan())
"

连接已配对设备

python -c "
import asyncio
from bleak import BleakClient
async def main():
    async with BleakClient('MAC地址', timeout=10.0) as c:
        print(f'已连接: {await c.get_device_name()}')
        for svc in c.services:
            for ch in svc.characteristics:
                if 'read' in ch.properties:
                    v = await c.read_gatt_char(ch.uuid)
                    print(f'  {ch.uuid}: {v.hex()[:60]}')
asyncio.run(main())
"
📎 文件位置
文件 路径
Python 包 C:\Users\64998\AppData\Local\Programs\Python\Python312\Lib\site-packages\bleak\
扫描脚本 F:\codex\tools\ble-scan\ (待创建)
📋 待办