bleak: BluetoothLEAdvertisementDataSection::data is corrupt, cannot be read with WinRT DataReader
- bleak version: 0.13.0
- Python version: 3.9.9
- Operating System: Microsoft Windows 10 Home (10.0.19043 N/A Build 19043)
- BlueZ version (
bluetoothctl -v) in case of Linux: N/A
Description
I am trying to access the BLE ServiceData (Data type: 0x16) from a BLE advertisement. I noticed that this works okay with Bleak v0.12.0 but running into trouble with Bleak v0.13.0. Everything else is the same, tried to uninstall and downgrade to v0.12.0 and the below code works but upgrading to v0.13.0 breaks DataReader.from_buffer() causing it to throw Runtime Error (not much information other than an error message stating “the parameter is incorrect”).
What I Did
# Requirements
# pip3 install winrt
# pip3 install bleak==0.13 // fails with this version
# pip3 install bleak==0.12 // works with this version
import asyncio
from bleak import BleakScanner
from winrt.windows.storage.streams import DataReader
# See https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.advertisement.bluetoothleadvertisement?view=winrt-19041
def detection_callback(device, advertisement_data):
for data_section in device.details.advertisement.data_sections:
print("Data type: ", data_section.data_type)
print("Data length: ", data_section.data.length)
dataReader = DataReader.from_buffer(data_section.data)
print("Data: ", " ".join([hex(dataReader.read_byte()) for i in range(data_section.data.length)]))
async def run():
scanner = BleakScanner(filters={"scanning_mode":"passive"})
scanner.register_detection_callback(detection_callback)
await scanner.start()
await asyncio.sleep(5)
await scanner.stop()
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 20
Write without response has to fit in a single packet while write with response can be split into multiple packets.
Looks like that worked. Thanks so much for the help! I am curious, why is it that the limit is different if there is a response?
Also, if anyone else is reading, it looks like my issue is NOT related to the one reported in this issue. Sorry for the confusion.