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!
Bleak is a GATT client software, capable of connecting to BLE devices acting as GATT servers. It is designed to provide a asynchronous, cross-platform Python API to connect and communicate with e.g. sensors.
BLE Scanner was developed with a vision to help Bluetooth community, developers who wants to build BLE products & applications. BLE Scanner is used by not only developers but also users are using it to find their lost Fitness Trackers and other Bluetooth Smart Devices.
PyBluez is a Python extension module written in C that provides access to system Bluetooth resources in an object oriented, modular manner.
To find BLE devices, you use the startScan() method. This method takes a ScanCallback as a parameter. You must implement this callback, because that is how scan results are returned.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With