BluetoothLEAdvertisementDataSection::data is corrupt, cannot be read with WinRT DataReader
See original GitHub issue- 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())
Issue Analytics
- State:
- Created 2 years ago
- Comments:20
Top Results From Across the Web
DataReader Class (Windows.Storage.Streams) - Microsoft Learn
Represents a referenced array of bytes used by byte stream read and write interfaces. Buffer is the class implementation of this interface. DataWriter...
Read more >c++ winrt - How to read byte data from a StorageFile in cppwinrt?
It appears the above sample code cannot function as it stands. In the documentation for FileIO I find it recommended to use DataReader...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.