This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to enable notification on NRF52832 peer?

Hi,

I develop application using BLE. In my scenario two NRF52832 operate in two different roles (Client and Server). I have ready to run app (as server) and can communicate with MCP on Android platform using notification. But have problem with enabling notification on NRF52832 (CENTRAL role). I do not need pairing devices nor storing communication parameters. It is enough that with each new connection I will enable/disable notification. How to do it? Many threads are discussing notifications on Android and/or iOS platforms. And how to enable notification on NRF52/51?

  • Yes, if you don't pair with device then you cannot assume it will remember GATT Server state after disconnecting. You simply find Client Characteristic Configuration Descriptor (CCCD) attached to Characteristic you want to enable Notifications on and write particular bit into it (Write or Write with Response (G)ATT methods should do the job). CCCD has 16-bit value, enable/disable Notifications bit is the lowest one (but remember that BLE uses little endian encoding so depending on data string interpretation you want to write 0x0001 or 0x0100).

  • Thank you for the hint. I found an example of how to do this. Unfortunately, in the example given there are "magic numbers":) In particular I do not know how to find a cccd handle for given characteristic (in the example == 16). Is the cccd handler always first on the list of handlers? Of course there is no problem with recomputing CRC-16 for different parameters.

  • Well normally there is no "key" how should be (G)ATT handles organized on Server side and they can even dynamically change over time. There is so-called Service Discovery procedure where Client (typically right after connection is established) uses ATT methods to enumerate some or all ATT handles. It typically looks for Primary Services (all their Characteristics and other objects are organized in a "block" before start of another Primary Service) by their 16 or 128-bit UUIDs (2 or 16 bytes). UUID is kind of "name" on GATT layer which is used by higher (GAP&APP) layer to work with counterpart on the other side of the link but on ATT/GATT itself everything is identified by handle number (16-bit value from 0x0001 to 0xFFFF). So if you know ATT handle number you can use it directly. If not then you are looking for specific Primary Service UUID, under it Characteristic UUID and under it...

  • ... CCCD UUID which is specified by BT SIG here (= 0x2902). Once you know handle number you can use Write or Write with Response to push 16-bit (2 byte) value.

  • Aaa, thanks a lot. Now I know where to go:)

Related