BLE device disconnects on Windows when sending a lot of writes #1156
-
DescriptionI´m using bleak to send 7 Byte packages to my BLE device. Here´s the Script i´m using: import asyncio
import sys
import logging
from bleak import BleakScanner, BleakClient
from bleak.backends.winrt.client import logger as bleak_log
DEFAULT_MAC = "05:55:F5:73:C5:E7"
UUID_WRITE = "0000ff02-0000-1000-8000-00805f9b34fb"
messages = [ bytes([19,6,0,0,0,25,1]),
bytes([19,6,0,0,1,26,1]),
bytes([19,6,0,0,2,27,1]),
bytes([19,6,0,0,3,28,1]),
bytes([19,6,0,0,4,29,1]),
bytes([19,6,0,0,5,30,1]),
bytes([19,6,0,0,6,31,1]),
bytes([19,6,0,0,7,32,1]),
bytes([19,6,0,0,8,33,1]),
bytes([19,6,0,0,9,34,1]),
bytes([19,6,0,0,10,35,1]),
bytes([19,6,0,0,11,36,1]),
bytes([19,6,0,0,12,37,1])]
# More messages in real script
async def main(ble_address: str):
# Logging
bleak_log.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(logging.Formatter('---BLEAK:%(levelname)s %(message)s'))
bleak_log.addHandler(ch)
bleak_log.disabled = False
print("Connecting")
device = await BleakScanner.find_device_by_address(ble_address, timeout=20.0)
async with BleakClient(device) as client:
print("\nSending")
i = 0
while True:
data = messages[i%len(messages)]
await client.write_gatt_char(UUID_WRITE, data)
i += 1
if __name__ == "__main__":
asyncio.run(main(sys.argv[1] if len(sys.argv) == 2 else DEFAULT_MAC)) On a Raspberry this script runs fine until manually stopped. On my Windows PC the BLE device is disconnected after sending some Messages. What I DidWhen running the Script on Windows i get the following output:
In a previous run I got the Following Traceback with an Windows Error after the disconnect:
LogsHere´s the Wireshark Capture File + a Capture File where I got the Windows error(bleaktest_packets2): |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
By default, |
Beta Was this translation helpful? Give feedback.
-
Hello, |
Beta Was this translation helpful? Give feedback.
-
I did run the script on a different Windows PC and did not have any issues even when lowering the |
Beta Was this translation helpful? Give feedback.
I did run the script on a different Windows PC and did not have any issues even when lowering the
asyncio.sleep()
time significantly. So what´s most likely the issue here is the Hardware used to send the signals.