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

Service handler missing in sd_ble_gatts_characteristic_add

Hi all,

I have been porting a project from SDK 8 to SDK12, andi have ported one of the services, however when i add a characteristic it throws

:ERROR:From File error 00000001 : ......\Watch_BLE\test_service.c:412

If i comment out that service, the nRF runs fine, and the device info service seems to work just fine.

I have followed the example in ble_bas.c to initialise the new service and the characteristics. Here is the init code for the service

	if (pTestService == NULL || p_test_init == NULL)
{
    return NRF_ERROR_NULL;
}

// Initialize service structure
pTestService->evt_handler = p_test_init->evt_handler;
pTestService->conn_handle = BLE_CONN_HANDLE_INVALID;
pTestService->is_notification_supported = p_test_init->support_notification;
// Add service
ble_uuid_t ble_service_uuid;
BLE_UUID_BLE_ASSIGN( ble_service_uuid, BLE_UUID_TEST_SERVICE );

uint32_t err_code = sd_ble_gatts_service_add( BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_service_uuid, &pTestService->service_handle );
APP_ERROR_CHECK(err_code);

pTestService->report_ref_handle = BLE_GATT_HANDLE_INVALID;

ble_gatts_char_md_t char_md;
ble_gatts_attr_md_t cccd_md;
ble_gatts_attr_md_t attr_md;
ble_gatts_attr_t    attr_char_value;

if (pTestService->is_notification_supported)
{
    memset(&cccd_md, 0, sizeof(cccd_md));

    // According to BAS_SPEC_V10, the read operation on cccd should be possible without
    // authentication.
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
    cccd_md.write_perm = p_test_init->battery_level_char_attr_md.cccd_write_perm;
    cccd_md.vloc       = BLE_GATTS_VLOC_STACK;
}

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

char_md.char_props.read   = 1;
char_md.char_props.notify = (pTestService->is_notification_supported) ? 1 : 0;
char_md.char_props.write  = 1;
char_md.char_props.write_wo_resp = 1;
char_md.p_char_user_desc  = NULL;
char_md.p_char_pf         = NULL;
char_md.p_user_desc_md    = NULL;
char_md.p_cccd_md         = (pTestService->is_notification_supported) ? &cccd_md : NULL;
char_md.p_sccd_md         = NULL;

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

attr_md.read_perm  = p_test_init->battery_level_char_attr_md.read_perm;
attr_md.write_perm = p_test_init->battery_level_char_attr_md.write_perm;
attr_md.vloc       = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth    = 0;
attr_md.wr_auth    = 0;
attr_md.vlen       = 0;

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

attr_char_value.p_uuid    = &ble_service_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len  = 20;
attr_char_value.init_offs = 0;
attr_char_value.max_len   = 20;
attr_char_value.p_value   = 0;

attr_char_value.p_uuid    = &UuidTestCharacteristicSWID;
err_code = sd_ble_gatts_characteristic_add( pTestService->service_handle, &char_md, &attr_char_value, &pTestService->swid_handles );
APP_ERROR_CHECK( err_code==NRF_SUCCESS );

And here is the code that calls that init function

 uint32_t err_code;
	 ble_test_init_t TestService_init;
	 memset(&TestService_init,0,sizeof(TestService_init));
	 TestService_init.evt_handler = (ble_test_evt_handler_t)TestService_on_ble_evt;
	 TestService_hCreate(&mTestService, &TestService_init);
	 

Softdevice is flashed from the same template project that i used as a base to port to, so compatibility should be fine.

Parents Reply Children
No Data
Related