BLE Descriptors on an ESP32
Posted: Thu Nov 18, 2021 2:48 pm
I'm trying to add a Characteristic Presentation Format descriptor to a characteristic.
My code looks like this:
Which should set the format to a single precision float. But when I connect to my ESP32 with NRF Connect on my phone, it shows the value (as hex), lists that it has a CPFD, but doesn't show the actual format. Trying to connect to it on my laptop in Python using Bleak, it ultimately reports a org.bluez.Error.NotPermitted error, which implies the READ flag isn't set on the descriptor. I have tried various combinations of flags, but I can't find the secret sauce.
Unfortunately I can't find any examples on setting descriptors, indeed on the web in general most tutorials just set the CCCD and leave it at that.
-JD
My code looks like this:
Code: Select all
_GNSS_BASE_UUID = ubluetooth.UUID("c33a0000-bda8-4293-b836-10dd6d78e7a1")
_GNSS_BASE_LATITUDE = (
ubluetooth.UUID(0x2AAE),
_FLAG_READ | _FLAG_NOTIFY,
((ubluetooth.UUID(0x2904), _FLAG_READ),)
)
_GNSS_BASE_SERVICE = (
_GNSS_BASE_UUID,
(_GNSS_BASE_LATITUDE,) )
)
class BLEGNSSBasePeripheral:
def __init__(self, ble, name="GNSSbase"):
self._ble = ble
self._ble.active(True)
((self._h_latitude, self._h_descr_latitude),) = self._ble.gatts_register_services((_GNSS_BASE_SERVICE,))
# Format as a 32-bit float, with 10^0 exponent, and as planar degrees.
self._ble.gatts_write(self._h_descr_latitude, struct.pack('<BbHBH', 20, 0, 0x2763, 1, 0x0000))
self._ble.gatts_write(self._h_latitude, struct.pack('<f', 23.42))
<etc>
Unfortunately I can't find any examples on setting descriptors, indeed on the web in general most tutorials just set the CCCD and leave it at that.
-JD