Environment details:
OS: Windows 11
Python version: 3.10.11
Bleak version: 0.20.1
Hardware: Polar H10 (Latest firmware)
PC Specs: MSI Katana A15 (AMD Ryzen 9 8945HS, MediaTek RZ616 Bluetooth Adapter) - Laptop. I suspect there might be a conflict between this specific hardware's driver and how WinRT handles GATT service caching when a device requires bonding, but im not entirely sure...
Description:
I am developing a real-time physiological monitoring system using a Polar H10 and Bleak. I am currently facing a Protocol Error 0x05 (Insufficient Authentication) when trying to enable the PMD (Polar Measurement Data) streams for both ECG and Accelerometer (ACC) data.
The Issue:
The connection is established successfully and I can read the battery level without issues. However, the moment I try to write the start commands to the PMD Control characteristic, the execution crashes.
Error Log:
Plaintext
File "...\bleak\backends\winrt\client.py", line 115, in _ensure_success
raise BleakError(
bleak.exc.BleakError: Could not write value bytearray(b'\x02\x00\x00\x01\x82\x00\x01\x01\x0e\x00') to characteristic 002E: Protocol Error 0x05: Insufficient Authentication
Configuration File (config_Polar.py):
Python
POLAR_MAC = "24:AC:AC:10:51:04"
# GATT UUIDs
PMD_UUID_CONTROL = "fb005c81-02e7-f387-1cad-8acd2d8df0c8"
PMD_UUID_DATA = "fb005c82-02e7-f387-1cad-8acd2d8df0c8"
# HEX Commands for PMD Handshake
# ECG: 130Hz
ECG_START_CMD = bytearray([0x02, 0x00, 0x00, 0x01, 0x82, 0x00, 0x01, 0x01, 0x0E, 0x00])
# ACC: 200Hz, 2G, 16-bit
ACC_START_CMD = bytearray([0x02, 0x02, 0x00, 0x01, 0xC8, 0x00, 0x01, 0x01, 0x10, 0x00, 0x02, 0x01, 0x08, 0x00])
Simplified Connector Logic:
Python
class PolarH10Connector:
def __init__(self, address):
self.address = address
self.client = BleakClient(address, timeout=30.0)
async def connect(self):
await self.client.connect()
# Adding await self.client.pair() here bypasses 0x05 but leads to a timeout loop
return self.client.is_connected
async def start_streams(self):
# Subscribe to PMD Data channel
await self.client.start_notify(config.PMD_UUID_DATA, self.pmd_data_callback)
# 1. Start ECG - Fails here with Error 0x05 (Insufficient Authentication)
await self.client.write_gatt_char(config.PMD_UUID_CONTROL, config.ECG_START_CMD, response=True)
await asyncio.sleep(0.5)
# 2. Start ACC - Also requires authentication
await self.client.write_gatt_char(config.PMD_UUID_CONTROL, config.ACC_START_CMD, response=True)
Observed Context:
Unpaired: Reading Battery level works, but writing to PMD Control triggers the 0x05 error.
Manually paired via OS Bluetooth settings: The connection or service discovery process hangs for a significant period before eventually failing with a TimeoutError. When the device is paired, the hang happens specifically during the service discovery phase. Even with use_cached_services=True, the backend seems to struggle to retrieve the service list, leading to the TimeoutError.
Using client.pair(): If I add await self.client.pair() in the code, the script moves past the 0x05 error initially, but then it triggers a different error.
The "Timeout Loop": Once the Windows pairing prompt is accepted, the device shows as "Connected" in the OS, but all subsequent attempts to run the script result in a permanent TimeoutError during connection or service discovery.
Once Windows marks the device as 'Connected', it seems to establish an exclusive lock. Even after killing the Python process, the sensor remains 'Connected' in the OS, and subsequent runs of the script cannot re-acquire the GATT session until the device is manually removed and re-paired.
Questions:
Does the Polar H10 require an explicit await client.pair() call within the script to authorize writes to the PMD Control point? I noticed that while it bypasses the 0x05 error once, I then fall into a TimeoutError loop.
Why would pairing the device cause BleakClient.connect() to timeout or hang in subsequent runs?
Is there any specific winrt backend flag to handle the bonding process more gracefully for sensors requiring authenticated writes?
Is there any alternative way to authorize these specific characteristics without relying on a persistent OS-level connection? In Windows 11, once the device is paired, the OS automatically establishes a connection. I haven't found a way to keep the device "Paired" but "Disconnected" to allow Bleak to manage the session exclusively without the system's interference, which seems to be the root of the TimeoutError.
Personal Note:
I'm sorry if I'm not expressing myself clearly—I'm just a biomedical engineer with little work experience, currently pursuing a master's degree in robotics and automation, and I don't know much about pure hardware... I apologize, and thank you to anyone who can help. I need to fix this so I can turn in my master’s thesis on time :(. My plan is to read data from the Polar H10 as close to real-time as possible to analyze it and derive a stress indicator based on HRV metrics, and using Bleak along with NeuroKit2 and pylsl is the best and fastest option I’ve found. I just hope I don't have to completely overhaul my architecture at this point, given how little time I have left to defend my thesis... :(
Environment details:
OS: Windows 11
Python version: 3.10.11
Bleak version: 0.20.1
Hardware: Polar H10 (Latest firmware)
PC Specs: MSI Katana A15 (AMD Ryzen 9 8945HS, MediaTek RZ616 Bluetooth Adapter) - Laptop. I suspect there might be a conflict between this specific hardware's driver and how WinRT handles GATT service caching when a device requires bonding, but im not entirely sure...
Description:
I am developing a real-time physiological monitoring system using a Polar H10 and Bleak. I am currently facing a Protocol Error 0x05 (Insufficient Authentication) when trying to enable the PMD (Polar Measurement Data) streams for both ECG and Accelerometer (ACC) data.
The Issue:
The connection is established successfully and I can read the battery level without issues. However, the moment I try to write the start commands to the PMD Control characteristic, the execution crashes.
Error Log:
Plaintext
Python
Observed Context:
Unpaired: Reading Battery level works, but writing to PMD Control triggers the 0x05 error.
Manually paired via OS Bluetooth settings: The connection or service discovery process hangs for a significant period before eventually failing with a TimeoutError. When the device is paired, the hang happens specifically during the service discovery phase. Even with use_cached_services=True, the backend seems to struggle to retrieve the service list, leading to the TimeoutError.
Using client.pair(): If I add await self.client.pair() in the code, the script moves past the 0x05 error initially, but then it triggers a different error.
The "Timeout Loop": Once the Windows pairing prompt is accepted, the device shows as "Connected" in the OS, but all subsequent attempts to run the script result in a permanent TimeoutError during connection or service discovery.
Once Windows marks the device as 'Connected', it seems to establish an exclusive lock. Even after killing the Python process, the sensor remains 'Connected' in the OS, and subsequent runs of the script cannot re-acquire the GATT session until the device is manually removed and re-paired.
Questions:
Does the Polar H10 require an explicit await client.pair() call within the script to authorize writes to the PMD Control point? I noticed that while it bypasses the 0x05 error once, I then fall into a TimeoutError loop.
Why would pairing the device cause BleakClient.connect() to timeout or hang in subsequent runs?
Is there any specific winrt backend flag to handle the bonding process more gracefully for sensors requiring authenticated writes?
Is there any alternative way to authorize these specific characteristics without relying on a persistent OS-level connection? In Windows 11, once the device is paired, the OS automatically establishes a connection. I haven't found a way to keep the device "Paired" but "Disconnected" to allow Bleak to manage the session exclusively without the system's interference, which seems to be the root of the TimeoutError.
Personal Note:
I'm sorry if I'm not expressing myself clearly—I'm just a biomedical engineer with little work experience, currently pursuing a master's degree in robotics and automation, and I don't know much about pure hardware... I apologize, and thank you to anyone who can help. I need to fix this so I can turn in my master’s thesis on time :(. My plan is to read data from the Polar H10 as close to real-time as possible to analyze it and derive a stress indicator based on HRV metrics, and using Bleak along with NeuroKit2 and pylsl is the best and fastest option I’ve found. I just hope I don't have to completely overhaul my architecture at this point, given how little time I have left to defend my thesis... :(