Hi,
I've been trying to build a custom characteristic and so far I can display a single digit number on my BLE app. My update value function looks like this:
uint32_t ble_cus_custom_value_update(ble_cus_t * p_cus, uint8_t custom_value)
{
NRF_LOG_INFO("In ble_cus_custom_value_update. \r\n");
if (p_cus == NULL)
{
return NRF_ERROR_NULL;
}
uint32_t err_code = NRF_SUCCESS;
ble_gatts_value_t gatts_value;
if (p_cus->conn_handle != BLE_CONN_HANDLE_INVALID)
{
// Initialize value struct.
memset(&gatts_value, 0, sizeof(gatts_value));
gatts_value.len = sizeof(uint8_t);
gatts_value.offset = 0;
gatts_value.p_value = &custom_value;
// Update database.
err_code = sd_ble_gatts_value_set(p_cus->conn_handle,
p_cus->custom_value_handles.value_handle,
&gatts_value);
APP_ERROR_CHECK(err_code);
if (notifications_enabled)
{
NRF_LOG_INFO("Sending notification for whatever");
uint16_t len = sizeof (uint8_t);
ble_gatts_hvx_params_t hvx_params;
memset(&hvx_params, 0, sizeof(hvx_params));
hvx_params.handle = p_cus->custom_value_handles.value_handle;
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
hvx_params.offset = 0;
hvx_params.p_len = &len;
hvx_params.p_data = custom_value;
err_code = sd_ble_gatts_hvx(p_cus->conn_handle, &hvx_params);
APP_ERROR_CHECK(err_code);
}
}
}
And my add function looks like this :
static uint32_t custom_value_char_add(ble_cus_t * p_cus)
{
uint32_t err_code;
ble_gatts_char_md_t char_md;
ble_gatts_attr_md_t cccd_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
uint8_t init_value = 0;
// Add Custom Value characteristic
memset(&char_md, 0, sizeof(char_md));
memset(&cccd_md, 0, sizeof(cccd_md));
memset(&attr_md, 0, sizeof(attr_md));
memset(&attr_char_value, 0, sizeof(attr_char_value));
// Set permissions on the CCCD and Characteristic value
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
// CCCD settings (needed for notifications and/or indications)
cccd_md.vloc = BLE_GATTS_VLOC_STACK;
// Characteristic Metadata
char_md.char_props.read = 1;
char_md.char_props.notify = 1;
char_md.p_char_user_desc = CustomCharName;
char_md.char_user_desc_size = sizeof(CustomCharName);
char_md.char_user_desc_max_size = sizeof(CustomCharName);
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = &cccd_md;
char_md.p_sccd_md = NULL;
// Define the Button ON press Characteristic UUID
ble_uuid.type = p_cus->uuid_type;
ble_uuid.uuid = CUSTOM_VALUE_CHAR_UUID;
// Attribute Metadata settings
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 0;
// Attribute Value settings
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = sizeof(uint8_t);
attr_char_value.init_offs = 0;
attr_char_value.max_len = sizeof(uint8_t);
attr_char_value.p_value = &init_value;
return sd_ble_gatts_characteristic_add(p_cus->service_handle, &char_md,
&attr_char_value,
&p_cus->custom_value_handles);
}
Now, how do I send a character say : char test[20] = "Hello, World!" via this instead of a number? Any leads?