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

How to disable indications inside central coming from the peripheral without disconnecting? I am using nRF52832.

In my current project, I am receiving multiple indications from peripheral device. After 25 indications, I need to pause the indications or disable the indications. I am using Soft Device S132. Is there any way?

I am using following code: 

static ret_code_t cccd_configure(uint16_t conn_handle, uint16_t cccd_handle, uint16_t hvx_type) {
  tx_message_t *p_msg;
  p_msg = &m_tx_buffer[m_tx_insert_index++];
  m_tx_insert_index &= TX_BUFFER_MASK;

  p_msg->req.write_req.gattc_params.handle = cccd_handle;
  p_msg->req.write_req.gattc_params.len = WRITE_MESSAGE_LENGTH;
  p_msg->req.write_req.gattc_params.p_value = p_msg->req.write_req.gattc_value;
  p_msg->req.write_req.gattc_params.offset = 0;
  p_msg->req.write_req.gattc_params.write_op = BLE_GATT_OP_WRITE_REQ;
  p_msg->req.write_req.gattc_value[0] = LSB_16(hvx_type);
  p_msg->req.write_req.gattc_value[1] = MSB_16(hvx_type);
  p_msg->conn_handle = conn_handle;
  p_msg->type = WRITE_REQ;

  tx_buffer_process();
  return NRF_SUCCESS;
}

ret_code_t ble_apg_c_indication_disable(ble_apg_c_t *p_ble_apg_c, uint16_t uuid_value) {
  VERIFY_PARAM_NOT_NULL(p_ble_apg_c);

  uint16_t cccd_handle = get_cccd_handle_to_indicate(p_ble_apg_c, uuid_value);
  if ((p_ble_apg_c->conn_handle == BLE_CONN_HANDLE_INVALID) || (cccd_handle == BLE_GATT_HANDLE_INVALID))
    return NRF_ERROR_INVALID_STATE;

  return cccd_configure(p_ble_apg_c->conn_handle, cccd_handle, 0);
}

  • And does that code work? What does it return?

    For comparison, what does your "enable indication" functions look like? 

  • Hi Edwin. Thanks for the valuable reply. I solved the issue. These functions are working OK. My enable indication function is same as disable function except instead '0', it passes BLE_GATT_HVX_INDICATION to cccd_configure function. 
    I want to disable the indication. But what happen is, when I acknowledge the first indication, the next came up. Now after acknowledging 5th indication, I am going to disable the indication. But as I acknowledged 5th indication, the sixth indication come up. I actually don't want sixth indication. Because of that after some time, as I haven't acknowledged that sixth indication, the peripheral gets disconnected because of supervision timeout. To solve this issue, what I did is, after 5th indication I firstly send disable indication, then acknowledged that fifth indication. So the sixth indication will never come.

  • ret_code_t ble_apg_c_indication_enable(ble_apg_c_t *p_ble_apg_c, uint16_t uuid_value) {
      VERIFY_PARAM_NOT_NULL(p_ble_apg_c);
    
      uint16_t cccd_handle = get_cccd_handle_to_indicate(p_ble_apg_c, uuid_value);
      if ((p_ble_apg_c->conn_handle == BLE_CONN_HANDLE_INVALID) || (cccd_handle == BLE_GATT_HANDLE_INVALID))
        return NRF_ERROR_INVALID_STATE;
    
      return cccd_configure(p_ble_apg_c->conn_handle, cccd_handle, BLE_GATT_HVX_INDICATION);
    }

Related