Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Is it possible to have a zero length characteristic read?

We're using the read authentication trigger to detect when a characteristic is being read, so we can update the value before a read.  Is it possible to have a read with zero length?

This is the data handler for the service, and I did confirm that it is getting called and that p_data and length are getting set to zero.

static bool CTFS_Data_Handler(ble_ctfs_evt_t *p_evt)
{
  bool b_ret_stat = false;

  switch (p_evt->type)
  {
    case READ_CHARACTERISTIC:
    p_evt->params.rw_data.p_data = 0;
    p_evt->params.rw_data.length = 0;
    break;

    default:
    break;
  }
}

The `CTFS_Data_Handler` gets passed to the softdevice as the data handler for this service.

void Service_Init()
{
  ble_uuid128_t mps_base_uuid = BLE_UUID_128_BIT_CTFS_BASE_SERVICE;

  /* Initialize the service structure. */
  m_ctfs.conn_handle = BLE_CONN_HANDLE_INVALID;
  m_ctfs.data_handler	= CTFS_Data_Handler;

  /* Add a custom base UUID. */
  uint32_t err_code = sd_ble_uuid_vs_add(&mps_base_uuid, &m_ctfs.uuid_type);
  VERIFY_SUCCESS(err_code);
}

But reading the characteristic always returns a byte.  Usually it's 0x00, but some times random data will also be returned.

Is there a way to have a zero-length characteristic read?  Or I guess another of putting it is return nothing on a read?

Parents Reply Children
Related