How to use python to scan and communicate with BLE device under Windows environment

19,404

Bleak is a Python package that supports BTLE on (not only) Windows. I tested the following code from the project page (after installing it with pip install bleak):

import asyncio
from bleak import BleakScanner

async def run():
    devices = await BleakScanner.discover()
    for d in devices:
        print(d)

loop = asyncio.get_event_loop()
loop.run_until_complete(run())

It successfully lists the discovered Bluetooth devices. Examples on how to connect are included in the Bleak project documentation.

Share:
19,404
Archiles heel
Author by

Archiles heel

Updated on December 02, 2022

Comments

  • Archiles heel
    Archiles heel over 1 year

    I'm a newbee for python. I searched a lot on website trying to find a way to scan and communicate with BLE device under Windows environment using python, however, almost all the results are under Linux or Android environments. The reason why I ask this question is because I already made a test architecture using python on windows, what I need is just to add a new test case for testing bluetooth LE device into my architecture. Any suggestions will be appreciated! Thanks!