Hi,
I want to set a custom value to my Gatt characteristic value. I can do this by writing to the characteristic in my app or the NRF_connect application.
What I want to do is based on an event or the data I receive to change the GATT characteristic data for my app to receive. I tried using this code which, did not change the data.
//err_code = ble_cus_custom_value_update(p_cus, p_ble_evt,m_custom_value);
//APP_ERROR_CHECK(err_code);
//I pass in a fixed value for testing into m_custom_value
uint32_t ble_cus_custom_value_update(ble_cus_t * p_cus, ble_evt_t const * p_ble_evt, 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;
// 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);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
// Send value if connected and notifying.
if ((p_cus->conn_handle != BLE_CONN_HANDLE_INVALID))
{
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 = gatts_value.offset;
hvx_params.p_len = &gatts_value.len;
hvx_params.p_data = gatts_value.p_value;
err_code = sd_ble_gatts_hvx(p_cus->conn_handle, &hvx_params);
}
else
{
err_code = NRF_ERROR_INVALID_STATE;
}
return err_code;
}
What I need to know is how to update this data value so I can transfer useful data between the two devices (mobile application and nordic board).
Note I am trying to do this within my GATT connection itself.
Note using SDK15 , PCA10056 NRF52840-dk Segger,
Thanks