How can I get my service characteristic value.

How do I get the value of the characteristic of the service I created? I try to get it with the following code, but the content pointer returned is NULL.

uint32_t gatts_char_value_get(uint16_t handle)
{
  uint32_t error_code = NRF_SUCCESS;
  ble_gatts_value_t r_value;
  r_value.p_value = NULL;
  error_code = sd_ble_gatts_value_get(BLE_CONN_HANDLE_INVALID, handle, &r_value);
  if (error_code != NRF_SUCCESS)
  {
    usb_printf_variadic("GATTS Value Get Error Code: 0x%04x", error_code);
    return error_code;
  }
  usb_printf_variadic("GATTS Value Get OK\n");
  NRF_LOG_INFO("P_Value Address: %p",r_value.p_value);
  usb_printf_variadic("Handle: %04X, Value Length: %d, Value: %s\n", handle, r_value.len, r_value.p_value);
  return error_code;
}

Related