9

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!

Archiles heel
  • 121
  • 1
  • 1
  • 4
  • This [link](http://christopherpeplin.com/2015/10/22/pygatt-python-bluetooth-low-energy-ble/) might help. – Nitish Kumar Apr 14 '17 at 19:46
  • Use the [PyGATT](https://github.com/peplin/pygatt) module. – Nitish Kumar Apr 14 '17 at 19:46
  • Thanks!! Will have a try. – Archiles heel Apr 14 '17 at 20:11
  • 3
    That works!I only want to return something that I found to help other freshmen like me. First you need to buy a BGAPI dongle if you want to connect with BLE device on windows through python. After plug your BGAPI dongle, you can try the following python code: import pygatt || adapter = pygatt.BGAPIBackend() || adapter.start() #start your dongle || adapter.scan() # you will get a result of nearby ble devices || device = adapter.connect(’xx:xx:xx:xx:xx:xx’)#input the device address you want to connect to || – Archiles heel Apr 28 '17 at 13:55

1 Answers1

5

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.

phispi
  • 604
  • 7
  • 15