← index #7220PR #17725
Off-topic · high · value 1.175
QUERY · ISSUE

BLE: Advertising name stays as 'ESP32'

openby plugowskiopened 2021-05-05updated 2021-05-10
extmod

I have an issue while advertise my device, I used ble_advertise helper from examples, which generates payload as below:

payload = b'\x02\x01\x06\x05\tLEDs\x11\x07\xdb\xa7\x7fgl\xbfG\x9c\x89@\x16\x05S@\x8a<'

So visible name in Bluetooth scanners should be LEDs but it is advertising as ESP32 all the time (I saw LEDs, few times only, after that it has been override as ESP32).

Any suggestions?

CANDIDATE · PULL REQUEST

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

mergedby dpgeorgeopened 2025-07-20updated 2025-07-31
docsexamples

Summary

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

The bug was reported here: https://github.com/raspberrypi/pico-micropython-examples/issues/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

<!-- If the Pull Request has some negative impact (i.e. increased code size)
then please explain why you think the trade-off improvement is worth it.
If you can think of alternative ways to do this, please explain that here too.

 Delete this heading if not relevant (i.e. small fixes) -->

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied