Skip to content

examples/bluetooth/ble_advertising.py: fix decoding of UUID32 #17725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dpgeorge
Copy link
Member

Summary

This fixes a long-standing bug in the BLE example, the part that decodes UUIDs.

The bug was reported here: raspberrypi/pico-micropython-examples#86

I also updated the relevant part of the documentation, about how UUIDs are constructed.

Testing

Tested with the following script:

import bluetooth
import ble_advertising

for uuid in (
    0x1234,
    b'\x34\x12',
    b'\x78\x56\x34\x12',
    b'1234567812345678',
    '6E400001-B5A3-F393-E0A9-E50E24DCCA9E',
):
    adv = ble_advertising.advertising_payload(name="test", services=[bluetooth.UUID(uuid)])
    try:
        print(ble_advertising.decode_services(adv))
    except Exception as er:
        print(er)

Prior to this fix the output was:

[UUID(0x1234)]
[UUID(0x1234)]
buffer too small
[UUID('38373635-3433-3231-3837-363534333231')]
[UUID('6e400001-b5a3-f393-e0a9-e50e24dcca9e')]

With the fix, the output is:

[UUID(0x1234)]
[UUID(0x1234)]
[UUID(0x12345678)]
[UUID('38373635-3433-3231-3837-363534333231')]
[UUID('6e400001-b5a3-f393-e0a9-e50e24dcca9e')]

Trade-offs and Alternatives

dpgeorge added 2 commits July 20, 2025 22:24
Signed-off-by: Damien George <damien@micropython.org>
The UUID32 case was incorrect: first, the "<d" should have been "<I", and
second, the UUID constructor treats integer arguments as UUID16.  So this
UUID32 case needs to pass in the actual data bytes.

And then it's simpler to just make all cases pass in the data bytes.

Signed-off-by: Damien George <damien@micropython.org>
Copy link

codecov bot commented Jul 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.44%. Comparing base (17fbc5a) to head (4d11dbe).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17725   +/-   ##
=======================================
  Coverage   98.44%   98.44%           
=======================================
  Files         171      171           
  Lines       22208    22208           
=======================================
  Hits        21863    21863           
  Misses        345      345           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs examples Relates to examples/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy