<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Adding custom UUID in the advertisement packet</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87681/adding-custom-uuid-in-the-advertisement-packet</link><description>Board: nRF52810 
 SoftDevice: s112 
 SDK version: 17.0.2 
 I&amp;#39;m trying to add a custom UUID in the advertisement packet and scan for the custom UUID in the central device to connect with it. I&amp;#39;ve followed the steps as given in the Tutorial . But my application</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 10 May 2022 12:19:32 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87681/adding-custom-uuid-in-the-advertisement-packet" /><item><title>RE: Adding custom UUID in the advertisement packet</title><link>https://devzone.nordicsemi.com/thread/367172?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 12:19:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9f7a1c4-00c9-486f-ad51-5212e7afca7e</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Yes, you need to specify the base UUID on the client side as well.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding custom UUID in the advertisement packet</title><link>https://devzone.nordicsemi.com/thread/367171?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 12:09:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34d57874-2cf0-4ec8-b570-61eb1ea5cfb6</guid><dc:creator>Nabeel Ar</dc:creator><description>&lt;p&gt;I&amp;#39;ve changed the service and advertising initialization order in main.c. I initialize advertising first and then service. Now it works fine.&amp;nbsp;&lt;/p&gt;
[quote userid="114062" url="~/f/nordic-q-a/87681/adding-custom-uuid-in-the-advertisement-packet"]In central, how can I scan for the custom UUID?[/quote]
&lt;p&gt;Should I need to add the base uuid in ble stack in central too??&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding custom UUID in the advertisement packet</title><link>https://devzone.nordicsemi.com/thread/367061?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 06:30:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c2b53842-77f5-46e9-b25b-d4961eda281b</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You need to replace &amp;#39;BLE_UUID_TYPE_VENDOR_BEGIN&amp;#39; with the &amp;#39;&lt;em&gt;p_uuid_type&lt;/em&gt;&amp;#39; value returned by&amp;nbsp;&lt;span class="item"&gt;&lt;a class="" title="sd_ble_uuid_vs_add" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.3.0/group___b_l_e___c_o_m_m_o_n___f_u_n_c_t_i_o_n_s.html?cp=4_7_3_1_2_0_2_2_8#ga265b4251110a15120d0aa97e5152163b"&gt;sd_ble_uuid_vs_add&lt;/a&gt;&lt;/span&gt;() in ble_cus.c to ensure you&amp;#39;re referencing the correct based UUID.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding custom UUID in the advertisement packet</title><link>https://devzone.nordicsemi.com/thread/367060?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 06:16:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03f98811-f607-4cc3-82ca-0b5943f989cd</guid><dc:creator>Nabeel Ar</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;This is my ble_cus.h file.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;quot;ble.h&amp;quot;
#include &amp;quot;ble_srv_common.h&amp;quot;

#define CUSTOM_SERVICE_UUID_BASE         {0xBC, 0x8A, 0xBF, 0x45, 0xCA, 0x05, 0x50, 0xBA, \
                                          0x40, 0x42, 0xB0, 0x00, 0xC9, 0xAD, 0x64, 0xF3}

#define CUSTOM_SERVICE_UUID               0x1400

/**@brief   Macro for defining a ble_cus instance.
 *
 * @param   _name   Name of the instance.
 * @hideinitializer
 */
#define BLE_CUS_DEF(_name)                                                                          \
static ble_cus_t _name;                                                                             \

/**@brief Custom Service init structure. This contains all options and data needed for
 *        initialization of the service.*/
typedef struct
{
    uint8_t                       initial_custom_value;           /**&amp;lt; Initial custom value */
    ble_srv_cccd_security_mode_t  custom_value_char_attr_md;     /**&amp;lt; Initial security level for Custom characteristics attribute */
} ble_cus_init_t;

/**@brief Custom Service structure. This contains various status information for the service. */
struct ble_cus_s
{
    uint16_t                      service_handle;                 /**&amp;lt; Handle of Custom Service (as provided by the BLE stack). */
    ble_gatts_char_handles_t      custom_value_handles;           /**&amp;lt; Handles related to the Custom Value characteristic. */
    uint16_t                      conn_handle;                    /**&amp;lt; Handle of the current connection (as provided by the BLE stack, is BLE_CONN_HANDLE_INVALID if not in a connection). */
    uint8_t                       uuid_type; 
};

// Forward declaration of the ble_cus_t type.
typedef struct ble_cus_s ble_cus_t;

/**@brief Function for initializing the Custom Service.
 *
 * @param[out]  p_cus       Custom Service structure. This structure will have to be supplied by
 *                          the application. It will be initialized by this function, and will later
 *                          be used to identify this particular service instance.
 * @param[in]   p_cus_init  Information needed to initialize the service.
 *
 * @return      NRF_SUCCESS on successful initialization of service, otherwise an error code.
 */
uint32_t ble_cus_init(ble_cus_t * p_cus, const ble_cus_init_t * p_cus_init);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is my ble_cus.c file&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;quot;sdk_common.h&amp;quot;
#include &amp;quot;ble_srv_common.h&amp;quot;
#include &amp;quot;ble_cus.h&amp;quot;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;

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-&amp;gt;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(&amp;amp;base_uuid, &amp;amp;p_cus-&amp;gt;uuid_type);
    VERIFY_SUCCESS(err_code);
    
    ble_uuid.type = p_cus-&amp;gt;uuid_type;
    ble_uuid.uuid = CUSTOM_SERVICE_UUID;

    // Add the Custom Service
    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &amp;amp;ble_uuid, &amp;amp;p_cus-&amp;gt;service_handle);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    return err_code;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve added all these in my main.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;quot;ble_cus.h&amp;quot;

BLE_CUS_DEF(m_cus);

ble_uuid_t m_adv_uuids[] = {{CUSTOM_SERVICE_UUID, BLE_UUID_TYPE_VENDOR_BEGIN }}; /**&amp;lt; Universally unique service identifiers. */

/**@brief Function for initializing the Advertising functionality.
 */
static void advertising_init(void)
{
    uint32_t               err_code;
    ble_advertising_init_t init;
    ble_cus_init_t     cus_init;
    
    err_code = ble_cus_init(&amp;amp;m_cus, &amp;amp;cus_init);
    APP_ERROR_CHECK(err_code);

    memset(&amp;amp;init, 0, sizeof(init));

    init.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    init.advdata.include_appearance = false;
    init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;

    init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.srdata.uuids_complete.p_uuids  = m_adv_uuids;

    init.config.ble_adv_fast_enabled  = true;
    init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;
    init.evt_handler = on_adv_evt;

    err_code = ble_advertising_init(&amp;amp;m_advertising, &amp;amp;init);
    APP_ERROR_CHECK(err_code);
   
    ble_advertising_conn_cfg_tag_set(&amp;amp;m_advertising, APP_BLE_CONN_CFG_TAG);
}&lt;/pre&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I didn&amp;#39;t add it to the services because I only need it to advertise it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding custom UUID in the advertisement packet</title><link>https://devzone.nordicsemi.com/thread/366929?ContentTypeID=1</link><pubDate>Mon, 09 May 2022 12:28:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dbab4aef-5ab6-4bf8-9349-c24a574f30c3</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Please post your main.c file.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding custom UUID in the advertisement packet</title><link>https://devzone.nordicsemi.com/thread/366924?ContentTypeID=1</link><pubDate>Mon, 09 May 2022 12:21:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f90494c2-3347-4d1a-8bd0-39e1dad434d2</guid><dc:creator>Nabeel Ar</dc:creator><description>&lt;p&gt;&lt;span&gt;I&amp;#39;ve increased the count in sdl_config.h file NRF_SDH_BLE_VS_UUID_COUNT. Now it works fine. But in the advertisement packet the&amp;nbsp;&lt;/span&gt;CUSTOM_SERVICE_UUID (16 bit UUID) is embedded into the UART base UUID (I&amp;#39;m also using this service but don&amp;#39;t want to advertise it) but not my custom UUID that I&amp;#39;ve added.&lt;/p&gt;
&lt;p&gt;How to add my custom UUID in the advertisement packet?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding custom UUID in the advertisement packet</title><link>https://devzone.nordicsemi.com/thread/366906?ContentTypeID=1</link><pubDate>Mon, 09 May 2022 11:35:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ad704b5-4285-4b22-b60e-4e915c5df47a</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Does it return NRF_ERROR_NO_MEM? In that case, you have to increase the NRF_SDH_BLE_VS_UUID_COUNT in your sdk_config.h and probably adjust the RAM start address (see debug log for details).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding custom UUID in the advertisement packet</title><link>https://devzone.nordicsemi.com/thread/366903?ContentTypeID=1</link><pubDate>Mon, 09 May 2022 11:26:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a7fe365-e774-4945-a866-aadf5c5ef8fd</guid><dc:creator>Nabeel Ar</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
[quote userid="4240" url="~/f/nordic-q-a/87681/adding-custom-uuid-in-the-advertisement-packet/366895#366895"]Sure you are not getting the assert in advertising_init()?[/quote]
&lt;p&gt;Yes, It gets asserted when I try to add base uuid in the ble stack.&lt;/p&gt;
&lt;p&gt;SVCALL(SD_BLE_UUID_VS_ADD, uint32_t, sd_ble_uuid_vs_add(ble_uuid128_t const *p_vs_uuid, uint8_t *p_uuid_type));&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding custom UUID in the advertisement packet</title><link>https://devzone.nordicsemi.com/thread/366895?ContentTypeID=1</link><pubDate>Mon, 09 May 2022 11:07:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bece4432-dc55-4d46-a22a-74b09be4adbe</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]Is it necessary to add my custom UUID in service init because I am only using it for connection purposes?[/quote]
&lt;p&gt;No, it&amp;#39;s only if the central needs the UUID to recognize your device. The central may also recognize it from the device name, address, etc.&lt;/p&gt;
[quote user=""]my application gets asserted when entering the advertising_start() function.&amp;nbsp;[/quote]
&lt;p&gt;Sure you are not getting the assert in advertising_init()? Either way, please include your code here so I can have a look.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>