Hello!
I am new to developing with BLE so any help to this frustrating problem would be greatly appreciated!
Firstly, I am using SDK16, Soft Device 113, v.7.0.1 on a custom prototype board using an nrf52832 module.
I've worked through some of the examples on creating a custom service and associated characteristics. The project compiles without
errors and I can see my device in nRF Connect. However, I can see only my custom service but not the characteristic I attached to it.
When I run the attach characteristic code, I get no error codes (just 0's).
static uint32_t red_char_add(ble_led_service_t * p_led_service) //might want init variable as well
{
ret_code_t err_code = 0;
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_gatts_attr_md_t attr_md;
ble_uuid_t ble_uuid;
memset(&char_md, 0, sizeof(char_md));
memset(&attr_char_value, 0, sizeof(attr_char_value));
memset(&attr_md, 0, sizeof(attr_md));
memset(&ble_uuid, 0, sizeof(ble_uuid));
char_md.char_props.read = 1;
char_md.char_props.write = 1;
char_md.p_char_user_desc = RedLedCharName;
char_md.char_user_desc_size = sizeof(RedLedCharName);
char_md.char_user_desc_max_size = sizeof(RedLedCharName);
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = NULL;
char_md.p_sccd_md = NULL;
// Attribute Metadata settings
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 0;
// Define RedLED UUID
ble_uuid.type = p_led_service->uuid_type;
ble_uuid.uuid = BLE_UUID_MAZU_HANDLE_RED_LED_CHAR;
// Set permissions on the Characteristic value
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
// Attribute Value settings
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = sizeof(uint16_t);
attr_char_value.init_offs = 0;
attr_char_value.max_len = sizeof(uint16_t);
attr_char_value.p_value = (uint8_t *)&redLedVal;
err_code = sd_ble_gatts_characteristic_add(p_led_service->service_handle, &char_md,
&attr_char_value,
&p_led_service->red_led_handle);
return err_code;
}
Similarly, my service registration code also works (with no errors):
void services_init(void)
{
ret_code_t err_code = 0;
nrf_ble_qwr_init_t qwr_init = {0};
// Initialize Queued Write Module.
qwr_init.error_handler = nrf_qwr_error_handler;
err_code = nrf_ble_qwr_init(&m_qwr, &qwr_init);
APP_ERROR_CHECK(err_code);
// Initialize Service structure and init structure to zero.
//memset(&ledServiceVarInit, 0, sizeof(ledServiceVarInit));
memset(&ledServiceVar, 0, sizeof(ledServiceVar));
//Initialize LED Service
err_code = ble_led_service_init(&ledServiceVar);
APP_ERROR_CHECK(err_code);
}
uint32_t ble_led_service_init(ble_led_service_t * p_led_service)
{
uint32_t err_code;
ble_uuid_t ble_uuid;
ble_uuid128_t base_uuid = {BLE_UUID_LED_SERVICE_BASE_UUID};
//Null check
if (p_led_service == NULL)
{
return NRF_ERROR_NULL;
}
// Initialize service structure
p_led_service->conn_handle = BLE_CONN_HANDLE_INVALID;
// Add service UUID
err_code = sd_ble_uuid_vs_add(&base_uuid, &p_led_service->uuid_type);
VERIFY_SUCCESS(err_code);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
// Set up the UUID for the service (base + service-specific)
ble_uuid.type = p_led_service->uuid_type;
ble_uuid.uuid = BLE_UUID_HANDLE_LED_SERVICE;
// Set up and add the service
err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_led_service->service_handle);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
// Add the different characteristics in the service:
err_code = red_char_add(p_led_service);
return err_code;
}
Again, any help would be greatly appreciated!