Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

How to make Service and Characteristic UUIDs show as 16-bit instead of 128-bit?

I currently am working on a BLE device in which I am trying to set the Service and Characteristic UUIDs. Here is an example of what I mean:

As can be seen here, the Service and Characteristic UUIDs are all custom 16-bit UUIDs.

However, when I try to create my own device with similar UUIDs as seen here (header file):

Here is the resulting ids sent:

As can be seen in the image above, the UUIDs that are set are sent, but it's being sent as a full 128 bits instead of the 16-bits as can be seen in the example.

Any help or guidance would be greatly appreciated!

  • Hello Tanjim,

    Thanks for your question.

    There is a similar case I answered before Nordic DevZone (nordicsemi.com). A UUID is a 128 value. However there are reserved UUIDs reserved by Bluetooth which contain 16 bits. You need to register to get this certified and which is really expensive How do I choose a UUID for my custom services and characteristics? - Novel Bits

    Best Regards,

    Kazi Afroza Sultana

  • Thank you, after looking at your previous response in that thread, I looked into the (components\ble\ble_services\ble_dfu\ble_dfu.c) code you mentioned and from it found the BLE_UUID_BLE_ASSIGN method. This method ended up working as I wanted.

    For people who find this thread in the future, here is the source code that I used to create the service:

    uint32_t ble_cus_init(ble_cus_t * p_cus, const ble_cus_init_t * p_cus_init)
    {
        if (p_cus == NULL || p_cus_init == NULL)
        {
            return NRF_ERROR_NULL;
        }
    
        uint32_t   err_code;
        ble_uuid_t ble_uuid;
    
        // Initialize service structure
        p_cus->evt_handler               = p_cus_init->evt_handler;
        p_cus->conn_handle               = BLE_CONN_HANDLE_INVALID;
    
        // Add Custom Service UUID
        ble_uuid128_t base_uuid = {CUSTOM_SERVICE_UUID_BASE};
    
        err_code =  sd_ble_uuid_vs_add(&base_uuid, &p_cus->uuid_type);
        VERIFY_SUCCESS(err_code);
        
        ble_uuid.type = p_cus->uuid_type;
        ble_uuid.uuid = CUSTOM_SERVICE_UUID;
    
        BLE_UUID_BLE_ASSIGN(ble_uuid, CUSTOM_SERVICE_UUID);
    
        // Add the Custom Service
        err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_cus->service_handle);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
    
        // Add Custom Value characteristic
        return custom_value_char_add(p_cus, p_cus_init);
    }

    You can set the characteristic UUIDs in a similar way. Just use the BLE_UUID_BLE_ASSIGN in the same way before the sd_ble_gatts_characteristic_add method. 

    Here is the resulting UUIDs from using this method:

Related