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

Problem!!! Connection handle invalid in nRF51822.

Hello All,

I am working on nRF51822. I used custom board in my project and this is customer requirement to use nRF51822. For reference nRF51 SDK 8.1.0 used and for programing IAR embedded workbench software version 7.40.3.8938 use in windows 7.

I am use ble_app_template this example for my project path is as like below,

..\nRF51_SDK_8.1.0_b6ed55f\examples\ble_peripheral\ble_app_template

I am add battery service and then upload program. I am also  create timer. after uploading program I do connection between nRF51822 and device (phone). and successfully connected. But problem is when I do enable notification from device value is change in fix interval and that should be send but value not display because in battery service connection event is not create while connection is already done successfully and device is continuously connected with custom board. when I read manually the value should be shown in device and code is as like show below,

uint32_t ble_bas_battery_level_update(ble_bas_t * p_bas, uint8_t battery_level)
{
uint32_t err_code = NRF_SUCCESS;
ble_gatts_value_t gatts_value;

if (battery_level != p_bas->battery_level_last)
{
// Initialize value struct.
memset(&gatts_value, 0, sizeof(gatts_value));

gatts_value.len = sizeof(uint8_t);
gatts_value.offset = 0;
gatts_value.p_value = &battery_level;

// Save new battery value.
p_bas->battery_level_last = battery_level;

// Update database.
err_code = sd_ble_gatts_value_set(p_bas->conn_handle,
p_bas->battery_level_handles.value_handle,
&gatts_value);
if (err_code != NRF_SUCCESS)
{
return err_code;
}

// Send value if connected and notifying.
if ((p_bas->conn_handle != BLE_CONN_HANDLE_INVALID))
{
if( p_bas->is_notification_supported)
{
ble_gatts_hvx_params_t hvx_params;

memset(&hvx_params, 0, sizeof(hvx_params));

hvx_params.handle = p_bas->battery_level_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_bas->conn_handle, &hvx_params);
}
}
else
{
err_code = NRF_ERROR_INVALID_STATE;
}
}

return err_code;

}

This function called at particulate time interval when as shown function if  p_bas->conn_handle != BLE_CONN_HANDLE_INVALID) this condition is true then check second condition but problem is this is condition is wrong at connection time.

 i am also trying to upload hrs program giving in SDK and then check battery service and enable notification in this all should be run and when value is change and show in device. I am also compare both program but program is same. Service initialization is same also.]

So please give me solution of my problem as soon as possible.

Thanks & best regards,

Urvisha Andani

Parents Reply Children
No Data
Related