This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Custom 128bits UUID

Hi, I have some problems to advertise a custom 128bit UUID. I succeeded to set the 128bit base UUID and my Characteristics UUIDs are 128bits. But how I can set the PrimaryService UUID to be 128 bits? I tried to set the returned type from sd_ble_uuid_vs_add() to ble_advdata_set() but it doesnt work.

Thanks, Eli

Parents
  • You can to set custom service UUID like this:

    uint32_t ble_cs_init(ble_cs_t * p_cs, const ble_cs_init_t * p_cs_init)
    {
        ble_uuid128_t   cs_base_uuid = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
                                        0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
    ...
        // Add custom base UUID.
        err_code = sd_ble_uuid_vs_add(&cs_base_uuid, &p_cs->uuid_type);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
    
        ble_uuid.type = p_cs->uuid_type;
        ble_uuid.uuid = BLE_UUID_CS_SERVICE;
        // Add service.
        err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                                            &ble_uuid,
                                            &p_cs->service_handle);
        /**@snippet [Adding proprietary Service to S110 SoftDevice] */
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
        // Add Characteristics.
    ...
    }
    

    UPD:

    To add your custom service UUID to advertising packets you need to do this:

    In ble_cs.h:

    #define BLE_UUID_CS_SERVICE            0x0001                       /**< The UUID of the Custom Service. */
    #define BLE_UUID_CS_TX_CHARACTERISTIC  0x0002                       /**< The UUID of the TX Characteristic. */
    #define BLE_UUID_CS_RX_CHARACTERISTIC  0x0003                       /**< The UUID of the RX Characteristic. */
    

    In main.c:

    static ble_cs_t                          m_cs;                                          /**< Structure to identify the Custom Service. */
    
    static void advertising_init(uint8_t adv_flags)
    {
        uint32_t      err_code;
        ble_advdata_t advdata;
    
        ble_uuid_t adv_uuids[] = 
        {
            {BLE_UUID_CS_SERVICE,                    m_cs.uuid_type}
        };
    ...
        advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
        advdata.uuids_complete.p_uuids  = adv_uuids;
        err_code = ble_advdata_set(&advdata, 0);
    ...
    }
    
    static void services_init(void)
    {
        uint32_t          err_code;
        ble_cs_init_t     cs_init;
    ...
        memset(&cs_init, 0, sizeof(cs_init));
    
        cs_init.data_handler = cs_data_handler;
        cs_init.initial_tx_char_val = a_send_onoff_mode;
        
        err_code = ble_cs_init(&m_cs, &cs_init);
        APP_ERROR_CHECK(err_code);
    }
    
  • What is BLE_UUID_SP_DATA_TYPE and BLE_UUID_SP_CMD_TYPE? Is it pointers to uuid_type from sd_ble_uuid_vs_add() call?

    When I'm using it for the ble_advdata_set() the device is not found by scanning.

    I think the problem may be that you have exceeded maximum advertising packet size and ble_advdata_set() call return an error and device reset from APP_ERROR_CHECK(err_code);. Check your app_error_handler() function.

Reply
  • What is BLE_UUID_SP_DATA_TYPE and BLE_UUID_SP_CMD_TYPE? Is it pointers to uuid_type from sd_ble_uuid_vs_add() call?

    When I'm using it for the ble_advdata_set() the device is not found by scanning.

    I think the problem may be that you have exceeded maximum advertising packet size and ble_advdata_set() call return an error and device reset from APP_ERROR_CHECK(err_code);. Check your app_error_handler() function.

Children
No Data
Related