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

How can I create a custom 128 bit base uuid?

Hello,

Please give detailed steps to create a custom 128-bit base UUID for our custom service and characteristics.

Parents
  • Hi,

    I recommend you refer to the ble_nus.c implementation which demonstrates usage of a custom 128 bit UUID. Referring to that what you need to add a 128 bit UUID is to fist add the base UUID:

        // Add a custom base UUID.
        err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_nus->uuid_type);
        VERIFY_SUCCESS(err_code);

    This adds the base and the "handle" for that base is put in the uuid_type varible, which is an output. This is essentially just a counter, and the first added base UUID will always be BLE_UUID_TYPE_VENDOR_BEGIN which is 2. . (This is why you see some example refer to BLE_UUID_TYPE_VENDOR_BEGIN instead of actually using the handle from the call to sd_ble_uuid_vs_add). If you add another custom base it will be 3 etc.

    Later when adding the service UUID you refer to the type to get the correct base:

       ble_uuid.type = p_nus->uuid_type;
        ble_uuid.uuid = BLE_UUID_NUS_SERVICE;
    
        // Add the service.
        err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                                            &ble_uuid,
                                            &p_nus->service_handle);

    and the same when adding characteristics:

        // Add the TX Characteristic.
        /**@snippet [Adding proprietary characteristic to the SoftDevice] */
        memset(&add_char_params, 0, sizeof(add_char_params));
        add_char_params.uuid              = BLE_UUID_NUS_TX_CHARACTERISTIC;
        add_char_params.uuid_type         = p_nus->uuid_type;
        add_char_params.max_len           = BLE_NUS_MAX_TX_CHAR_LEN;
        add_char_params.init_len          = sizeof(uint8_t);
        add_char_params.is_var_len        = true;
        add_char_params.char_props.notify = 1;
    
        add_char_params.read_access       = SEC_OPEN;
        add_char_params.write_access      = SEC_OPEN;
        add_char_params.cccd_write_access = SEC_OPEN;
    
        return characteristic_add(p_nus->service_handle, &add_char_params, &p_nus->tx_handles);
        /**@snippet [Adding proprietary characteristic to the SoftDevice] */

    Einar

  • Einar thanks for the reply, but what I really want is the method to create a 128bit base UUID 

Reply Children
No Data
Related