Skip to content

fix(winrtble): open GATT services before characteristics discovery - #507

Open
robdobsn wants to merge 1 commit into
deviceplug:masterfrom
robdobsn:fix/winrtble-open-gatt-service
Open

robdobsn wants to merge 1 commit into
deviceplug:masterfrom
robdobsn:fix/winrtble-open-gatt-service

Conversation

@robdobsn

Copy link
Copy Markdown

Problem

On Windows, discover_services() returns a custom service with no characteristics on some peripherals. GetCharacteristicsWithCacheModeAsync returns GattCommunicationStatus::AccessDenied for the service, which is only logged at debug level, so the service just looks empty. The standard GAP and GATT services on the same device are fine.

Changes

get_characteristics now opens each service with OpenAsync(GattSharingMode::SharedReadAndWrite) before discovering its characteristics. Shared mode doesn't stop other apps using the service. If opening fails, discovery is tried as before, so behavior is unchanged for devices that didn't need it.

Validation

I hit this with ESP32-S3 peripherals running NimBLE (a 128-bit service with a write characteristic and a notify/indicate one), on Windows 11 (build 26200) with an Intel adapter. With 0.11.8 and 0.13.5 the service had no characteristics on every connection (0 of 6). With this change, characteristic discovery worked on every connection, about 20 at first, and many more since across two devices, including writes, notifications and transfers of over 1 MB. Calling RequestAccessAsync first didn't help (0 of 2). The bluest crate gets the same AccessDenied on these devices, so it seems to be WinRT requiring the open for some services rather than anything specific to btleplug.

cargo test --lib passes on Windows.

…stics

Some peripherals' services refuse GetCharacteristicsWithCacheModeAsync with
GattCommunicationStatus::AccessDenied until the service has been opened, so
discover_services() returned the service with no characteristics. Open each
service with GattSharingMode::SharedReadAndWrite first. If opening fails,
discovery is tried as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant