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

How to enable indication for a characteristic

Hello Everyone

Is there any example code which uses indication property. Application nAn-36 uses notification property and as far as i read and understood about indication property it will indicate any change in the characteristic of service made by client to the Server.

Enabling the GATT characteristic to indicate state, what other things i need to do. such as

char_md.char_props.indicate = 1;

So that whenever a value changes it will be indicated automatically.

Thanks & Regards Asma

Parents
  • Doing a quick search in the SDK, I see that multiple profiles are using the indications. This includes BPS, CGM, GLS, HTS and the DFU example to mention a few.

    In general, it is enough to set the indicate bit and a writable CCCD for the characteristic in question. This will add an indicatable characteristic.

    However, before you are able to send an indication with sd_ble_gatts_hvx() and hvx_params.type = BLE_GATT_HVX_INDICATION, the peer you have connected to must write to the CCCD of the characteristic, enabling indications. The CCCD value is a bitfield, and indications are the second bit. So any value like 0x02 (indications only) and 0x03 (indications and notifications) should enable indication.

    You are also not allowed to send a new indication until the previous one is confirmed. This is signaled by the reception of a BLE_GATTS_EVT_HVC (handle value confirmation) event.

    For more information, refer to the API documentation for sd_ble_gatts_hvx.

Reply
  • Doing a quick search in the SDK, I see that multiple profiles are using the indications. This includes BPS, CGM, GLS, HTS and the DFU example to mention a few.

    In general, it is enough to set the indicate bit and a writable CCCD for the characteristic in question. This will add an indicatable characteristic.

    However, before you are able to send an indication with sd_ble_gatts_hvx() and hvx_params.type = BLE_GATT_HVX_INDICATION, the peer you have connected to must write to the CCCD of the characteristic, enabling indications. The CCCD value is a bitfield, and indications are the second bit. So any value like 0x02 (indications only) and 0x03 (indications and notifications) should enable indication.

    You are also not allowed to send a new indication until the previous one is confirmed. This is signaled by the reception of a BLE_GATTS_EVT_HVC (handle value confirmation) event.

    For more information, refer to the API documentation for sd_ble_gatts_hvx.

Children
  • Thank you Ulrich for this information. one more doubt i have is BLE_GATTS_EVT_HVC is generated after the indication value is sent and acknowledgement is received. if it is so then why do in ble_bps_app project on BLE_GATTS_EVT_HVC on_hvc handler is called and in that handler bps_measurement_send function is called which send blood pressure values.

    can anyone please tell me the how indication works. API documentation do not provide in detail information.

    Thanks & Regards Asma

  • The BPS example is sending an initial indication on the custom BLE_BPS_EVT_INDICATION_ENABLED event, and then an additional indication for every button press (if no indications are pending).

    The Bluetooth Spec will tell you more about indications, but in short, indications are very much like notifications. The notable difference is that indications must be ACKed, where notifications can be sent as fast as the peer can receive. Indications are good for when receiving a value is expensive, or when you need extra time before getting the rest of the data. Maybe you need to boot up a display to display it. Notifications are good when you want to send an update whenever you have something to send, or if you want to send data very fast.

    It is possible to have characteristics that are both notifiable and indicatable, and the peer decides by writing to the CCCD.

  • ok...but when i checked it on MCP it only sends data whenever a push button1 is pressed and not continuously. Now as per my understanding whenever any indication is sent and acknowledge BLE_GATTS_EVT_HVC will be generated and then i can write my own code in this event to know that data has been received and acknowledged by peer device. Is it right?

  • I mistook the example for another and have edited my comment. But you are right in that the event will come whenever the peer has acknowledged the indication. You just have to remember that you are also allowed to send indications as soon as the CCCD is written correctly to, or when you restore system parameters right after connecting. After that you must wait for events before you can send new ones.

Related