spacecheese / bluez_peripheral

A library for building BLE peripherals using GATT and bluez
MIT License
38 stars 8 forks source link

Advertising Packet Length #26

Closed Sintaxya closed 1 year ago

Sintaxya commented 1 year ago

I have a BLE device which I wrote a Service for using bluez_peripheral, everything works smoothly until I try to change my manufacturer data or add service data.

Current Manufacturer data: MANUFACTURER_DATA = {0xFFFF: b'CP'}

However, when I change the b'CP' to anything longer, the Advertisement fails: Failed to parse advertisement. Example: MANUFACTURER_DATA = {0xFFFF: b'CPA'}

I don't exactly know the root of this issue, as, for example, i can safely change the local name of the device which is also part of the advertisement without any issues.

My advertisement:

self.my_advertisement = Advertisement(localName=self.local_name,
                                                serviceUUIDs=SERVICE_ID,
                                                appearance=SERVICE_APPEARANCE,
                                                timeout=self.service_timeout,
                                                discoverable=True,
                                                manufacturerData=MANUFACTURER_DATA)
self.local_name = "RPI BLE Device"
MANUFACTURER_DATA = {0xFFFF: b'CP'}

SERVICE_ID = [MY_SERVICE_UUID]

SERVICE_APPEARANCE = 0

MY_SERVICE_UUID = "6E400000-8675-47AA-8375-2D200D18D555"

Error:

File "/usr/local/lib/python3.9/site-packages/bluez_peripheral/advert.py", line 119, in register
    await interface.call_register_advertisement(path, {})
  File "/usr/local/lib/python3.9/site-packages/dbus_next/aio/proxy_object.py", line 92, in method_fn
    BaseProxyInterface._check_method_return(msg, intr_method.out_signature)
  File "/usr/local/lib/python3.9/site-packages/dbus_next/proxy_object.py", line 62, in _check_method_return
    raise DBusError._from_message(msg)
spacecheese commented 1 year ago

Hello and sorry for the slow response.

This is a limitation of the BLE protocol- advertising payloads are limited to 31 octets (Core Spec Vol 6, Part B, Figure 2.6). I'm not so familiar with this spec so its a little tricky figuring out exactly where these bytes are going but my guess is:

Sintaxya commented 1 year ago

Thank you for the answer. I switched from 128 bit UUID to 16 bit (gaining a few octets of length to be used in the process), and I could make the Manufacturer Data longer, as I wanted.