Please tell me how to set 128bit UUID to "ble_uuid_t" in [Function for adding the Custom Value characteristic].

OS in development environment :Windows10
HARD :(Taiyo Yuden)EBSHSN Series Evaluation Board : Central / Peripherals
CPU :(Nordic) nRF52832 / ARMR Cortex-M4F 32 bit processor 28-pin Land Grid Array / 15GPIOs / SWD
builder :SEGGER Embedded Studio for ARM Release 3.34a Build 2018022300.35192 Windows x64
Copyright 2014-2018 SEGGER Microcontroller GmbH & Co. KG
Copyright 1997-2018 Rowley Associates Ltd.
GCC/BINUTILS: Built using the GNU ARM Embedded Toolchain version 6-2017-q2-update source distribution
Clang/LLVM: Built using the version 5.0.0 source distribution
Soft Ver:nRF5_SDK_15.3.0_59ac345

I thought about it with reference to [Common type and macro definition> Definition], but I think that it will affect related programs if the [p_cus-> uuid_type] part of the 16-bit setting is not performed even with the 128-bit setting.

(For 16bit)
    ble_uuid_t ble_uuid;
    ble_uuid.type = p_cus->uuid_type;
(For 128bit)
    ble_uuid_t ble_uuid;
    ble_uuid.type = BLE_UUID_TYPE_VENDOR_BEGIN;

Please tell me the setting method for 128bit.
Thanking you in advance.

Parents
  • Hi Toshikazu, 

    Could you give me more context of how you use the ble_uuid.type code ? 

    If you have a look at the ble_nus.c example you can find that we call : ble_uuid.type = p_nus->uuid_type; where p_nus->uuid_type is the output from the function sd_ble_uuid_vs_add(). When you declare a new 128bit UUID by using sd_ble_uuid_vs_add() it will assign a UUID base index into p_nus->uuid_type. 

    So it's not always that you have ble_uuid.type = BLE_UUID_TYPE_VENDOR_BEGIN; . The index for 128 bit UUID starts at  BLE_UUID_TYPE_VENDOR_BEGIN (2) but it doesn't mean that it's always 2, if you declare 2 UUID bases, the second UUID base will get the index (uuid_type) = 3 

  • The application on the tablet side is designed to communicate using the UUID (128bit) unique to each item of CUS communication.
    Please tell me how to set a unique UUID (128bit) for each CUS communication item and communicate.

  • Mr. Hung Bui
    I checked [ble_nus.c].
    128bit UUID is set in [NUS_BASE_UUID], but 16bit UUID is set in the communication item UUID. Is there a way to set 128bit UUID for each communication item?
    128bit UUID is set for each item in the communication application on the tablet side.
    ------------------------------------------
    #define BLE_UUID_NUS_TX_CHARACTERISTIC 0x0003 /**< The UUID of the TX Characteristic. */
    #define BLE_UUID_NUS_RX_CHARACTERISTIC 0x0002 /**< The UUID of the RX Characteristic. */
    #define NUS_BASE_UUID {{0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E}} /**< Used vendor specific UUID. */
    -----------------------------------------
    Thanking you in advance.

  • Hi Toshikazu, 

    The way it works in our softdevice is that you add a 128 bits (16 bytes) base UUID into the softdevice and you declare a 16 bits  UUID of the service/characteristic on top of that.

    This 16 bits UUID will be place in byte 12th and 13th in the UUID base and this will create a full 128 bit UUID for the service/characteristic. 

    For example if the base is: 
    0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E

    And the TX characteristic has 16 bit UUID 0x0003 . 

    The full UUID of the characteristic will be: 
    0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, 0x03, 0x00, 0x40, 0x6E


    Do you have a requirement that each of your characteristic should have different base UUIDs ? 

    If it's the case you may need to define multiple of them using sd_ble_uuid_vs_add() and then use the correspondent uuid_type for each of the characteristic declaration. 

  • Mr. Hung Bui
    It seems that I was not able to ask the question correctly, so I will ask again

    Please tell me how to set the following conditions and how to communicate.
    [conditions]
    1) Communicate using your own UUID, not the UUID issued by the Bluetooth SIG.
    2) A unique 128-bit UUID is set for each item.
    3) I want to communicate using 19 unique UUIDs (128 bits)
    (Because the existing application is used, it is necessary to create it according to the application)
    Thank you.

  • Hi Toshikazu, 

    I'm sorry that my suggestion was not clear enough. Let me try again. 

    It's possible to add multiple unique 128 bits UUID. You just need to add each of the UUID base using sd_ble_uuid_vs_add() function and  then use the correspondent uuid_type for each of the characteristic/service declaration. 

     For example this code will add 2 services with different UUIDs: 

    ble_uuid128_t nus_base_uuid1 = NUS_BASE_UUID1;
    
    ble_uuid128_t nus_base_uuid2 = NUS_BASE_UUID2;
    
    /**@snippet [Adding proprietary Service to the SoftDevice] */
    // Add a custom base UUID.
    err_code = sd_ble_uuid_vs_add(&nus_base_uuid1, &p_nus1->uuid_type);
    VERIFY_SUCCESS(err_code);
    
    err_code = sd_ble_uuid_vs_add(&nus_base_uuid2, &p_nus2->uuid_type);
    VERIFY_SUCCESS(err_code);
    
    ble_uuid1.type = p_nus1->uuid_type;
    ble_uuid1.uuid = BLE_UUID_NUS_SERVICE1;
    
    ble_uuid2.type = p_nus2->uuid_type;
    ble_uuid2.uuid = BLE_UUID_NUS_SERVICE2;
    
    // Add the service.
    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
    &ble_uuid1,
    &p_nus1->service_handle);
    
    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
    &ble_uuid2,
    &p_nus2->service_handle);

    In this case, when you call sd_ble_uuid_vs_add() the p_nus1->uuid_type will have value 2 (BLE_UUID_TYPE_VENDOR_BEGIN) and then the second call p_nus2->uuid_type  will have value 3. 
    It's the index of the UUID base in the softdevice. After each call this index will be increased by one. 
    So you will need to add 19 UUID using 19 sd_ble_uuid_vs_add() calls. 

    Please notice the way the base UUID and the 16 bit UUID form the complete 128 bit UUID as I explained earlier. 

    It's quite a large attribute table with 19 different UUIDs. You may need to increase: 
    - NRF_SDH_BLE_VS_UUID_COUNT

    - NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE

    in sdk_config.h

    So that the softdevice can handle this large number of service/characteristics. However please try to test first with a few of them. 

  • Mr. Hung Bui
    I don't know how to set [p_nus1] [p_nus1].
    In the case of [ble_nus.c]
     -Create "m_nus" by "BLE_NUS_DEF (m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT);" in "main.c" of "ble_app_uart".
     -Pass "m_nus" to [ble_nus.c] and change it to [p_nus] for use.
    I don't know the processing content of "BLE_NUS_DEF (m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT);", so please tell me how to set it.
    Thank you.

Reply
  • Mr. Hung Bui
    I don't know how to set [p_nus1] [p_nus1].
    In the case of [ble_nus.c]
     -Create "m_nus" by "BLE_NUS_DEF (m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT);" in "main.c" of "ble_app_uart".
     -Pass "m_nus" to [ble_nus.c] and change it to [p_nus] for use.
    I don't know the processing content of "BLE_NUS_DEF (m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT);", so please tell me how to set it.
    Thank you.

Children
  • Hi Toshikazu,

    I was using p_nus1 as an example, in case you want to have multiple instance of ble_nus_t. 
    What BLE_NUS_DEF () does it to define the m_nus instance (that maintain the link context usually if you have only one single connection you don't have to worry about it) and setup a NRF_SDH_BLE_OBSERVER with the name ble_nus_on_ble_evt(). 

    So in your case, when you have 19 UUIDs, how many services and how many characteristics you will have ? 
    For each service you may want to define something similar to a ble_nus.c file, but for your own services. 

    Make sure you know how to use sd_ble_uuid_vs_add(). I would suggest you to play a little bit more with the ble_nus example. For example you can try to test adding 1-2 more characteristics to the NUS service. Each of them should have different UUID base. 

  • Please tell me about instance definition and settings.
    -I tried to define and secure instances of 9 items, is there any problem?

    /-*< 9 custom service instance definition >*-/
    #define BLE_CUS1_DEF(_name) static ble_cus_t _name; NRF_SDH_BLE_OBSERVER(_name ## _obs, BLE_HRS_BLE_OBSERVER_PRIO, ble_cus1_on_evt, &_name) /* Item1 */
    #define BLE_CUS2_DEF(_name) static ble_cus_t _name; NRF_SDH_BLE_OBSERVER(_name ## _obs, BLE_HRS_BLE_OBSERVER_PRIO, ble_cus2_on_evt, &_name) /* Item1 */
    #define BLE_CUS3_DEF(_name) static ble_cus_t _name; NRF_SDH_BLE_OBSERVER(_name ## _obs, BLE_HRS_BLE_OBSERVER_PRIO, ble_cus3_on_evt, &_name) /* Item1 */
    #define BLE_CUS4_DEF(_name) static ble_cus_t _name; NRF_SDH_BLE_OBSERVER(_name ## _obs, BLE_HRS_BLE_OBSERVER_PRIO, ble_cus4_on_evt, &_name) /* Item1 */
    #define BLE_CUS5_DEF(_name) static ble_cus_t _name; NRF_SDH_BLE_OBSERVER(_name ## _obs, BLE_HRS_BLE_OBSERVER_PRIO, ble_cus5_on_evt, &_name) /* Item1 */
    #define BLE_CUS6_DEF(_name) static ble_cus_t _name; NRF_SDH_BLE_OBSERVER(_name ## _obs, BLE_HRS_BLE_OBSERVER_PRIO, ble_cus6_on_evt, &_name) /* Item1 */
    #define BLE_CUS7_DEF(_name) static ble_cus_t _name; NRF_SDH_BLE_OBSERVER(_name ## _obs, BLE_HRS_BLE_OBSERVER_PRIO, ble_cus7_on_evt, &_name) /* Item1 */
    #define BLE_CUS8_DEF(_name) static ble_cus_t _name; NRF_SDH_BLE_OBSERVER(_name ## _obs, BLE_HRS_BLE_OBSERVER_PRIO, ble_cus8_on_evt, &_name) /* Item1 */
    #define BLE_CUS9_DEF(_name) static ble_cus_t _name; NRF_SDH_BLE_OBSERVER(_name ## _obs, BLE_HRS_BLE_OBSERVER_PRIO, ble_cus9_on_evt, &_name) /* Item1 */

    /-*< 9 custom service instance reservation >*-/
    BLE_CUS1_DEF(m_cus1); /*< 1st custom service instance */
    BLE_CUS2_DEF(m_cus2); /*< 2nd custom service instance */
    BLE_CUS3_DEF(m_cus3); /*< 3rd custom service instance */
    BLE_CUS4_DEF(m_cus4); /*< 4th custom service instance */
    BLE_CUS5_DEF(m_cus5); /*< 5th custom service instance */
    BLE_CUS6_DEF(m_cus6); /*< 6th custom service instance */
    BLE_CUS7_DEF(m_cus7); /*< 7th custom service instance */
    BLE_CUS8_DEF(m_cus8); /*< 8th custom service instance */
    BLE_CUS9_DEF(m_cus9); /*< 9th custom service instance */

  • Hi,

    I'm not sure what you are trying to do.

    If you want to add multiple services with different UUID base then you have to follow Hungs example here:

    Hung Bui said:
     For example this code will add 2 services with different UUIDs: 

    I strongly suggest that you also go through our 3 part tutorial on Advertising, Service, and Characteristics. I especially recommend going through the service tutorial. It shows you how to setup a custom service with custom UUID. 

    regards

    Jared

Related