I am trying to receive ble notifications from a custom UUID as a central device and then relay that information to my computer via ble. I have been following the nordic relay example and have been mostly successful. I run into problems when I try and connect to a custom UUID. The problem is that custom service starts at the FIRST index of the 128 bit UUID rather than the second. I have been following the ble_nus_c.c program to get this working with no luck. Here is my relevant code to initialize the service:
uint32_t ble_nus_c_init(ble_nus_c_t * p_ble_nus_c, ble_nus_c_init_t * p_ble_nus_c_init)
{
uint32_t err_code;
ble_uuid_t uart_uuid;
ble_uuid128_t nus_base_uuid = CUST_BASE_UUID;
VERIFY_PARAM_NOT_NULL(p_ble_nus_c);
VERIFY_PARAM_NOT_NULL(p_ble_nus_c_init);
p_ble_nus_c->uuid_type = 0x01; //service starts here rather than 0x02
err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_ble_nus_c->uuid_type);
VERIFY_SUCCESS(err_code);
uart_uuid.type = p_ble_nus_c->uuid_type;
uart_uuid.uuid = BLE_UUID_NUS_SERVICE;
p_ble_nus_c->conn_handle = BLE_CONN_HANDLE_INVALID;
p_ble_nus_c->evt_handler = p_ble_nus_c_init->evt_handler;
p_ble_nus_c->handles.nus_rx_handle = BLE_GATT_HANDLE_INVALID;
p_ble_nus_c->handles.nus_tx_handle = BLE_GATT_HANDLE_INVALID;
return ble_db_discovery_evt_register(&uart_uuid);
}
and here is the code to discover the characteristic and enable notifications:
void ble_nus_c_on_db_disc_evt(ble_nus_c_t * p_ble_nus_c, ble_db_discovery_evt_t * p_evt)
{
ble_nus_c_evt_t nus_c_evt;
memset(&nus_c_evt,0,sizeof(ble_nus_c_evt_t));
ble_gatt_db_char_t * p_chars = p_evt->params.discovered_db.charateristics;
// Check if the NUS was discovered.
if (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE &&
p_evt->params.discovered_db.srv_uuid.uuid == CUST_BASE_UUID &&
p_evt->params.discovered_db.srv_uuid.type == p_ble_nus_c->uuid_type)
{
uint32_t i;
for (i = 0; i < p_evt->params.discovered_db.char_count; i++)
{
switch (p_chars[i].characteristic.uuid.uuid)
{
case BLE_UUID_NUS_TX_CHARACTERISTIC:
nus_c_evt.handles.nus_tx_handle = p_chars[i].characteristic.handle_value;
break;
case BLE_UUID_CUST_CHARACTERISTIC:
nus_c_evt.handles.nus_rx_handle = p_chars[i].characteristic.handle_value;
nus_c_evt.handles.nus_rx_cccd_handle = p_chars[i].cccd_handle;
break;
default:
break;
}
}
if (p_ble_nus_c->evt_handler != NULL)
{
nus_c_evt.conn_handle = p_evt->conn_handle;
nus_c_evt.evt_type = BLE_NUS_C_EVT_DISCOVERY_COMPLETE;
p_ble_nus_c->evt_handler(p_ble_nus_c, &nus_c_evt);
}
}