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

I want to conditionally switch the advertised UUID to another UUID.

Hello.
It is developed using nrf52832 (S132 v7.0.1, SDK v17.0.0) as a peripheral device.

I want to conditionally switch the advertised UUID to another UUID.
There is "sd_ble_uuid_vs_add" as an API to set the advertisement UUID, but I don't know how to change the advertised UUID once set. Is there a way to change it?

Best regards.

Parents
  • Hello,

    I want to conditionally switch the advertised UUID to another UUID.
    There is "sd_ble_uuid_vs_add" as an API to set the advertisement UUID

    The contents of the advertising payload and the added vendor specific UUID are independent of each other. The sd_ble_uuid_vs_add function adds the vendor specific UUID to the SoftDevice table - it does not populate the advertising payload.
    The advertising payload will have to be populated separately, where you can add which ever valid data field to the payload as you would like. You could see this done in the advertising_init function of the BLE peripheral examples in the SDK.
    If you are using the BLE advertising library you could also take a look at this blogpost to see how you may dynamically update your advertising payload, along with an example of this.

    Best regards,
    Karl

  • Hello.

    I misunderstood that if I did sd_ble_uuid_vs_add at the very beginning, it would set the advertised UUID. I have listed the current advertising_init code.

    #define BLE_BASE_UUID  {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15}
    #define BLE_ADV_UUID   0xFFFF
    BLE_ADVERTISING_DEF(m_advertising);
    
    // Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs.
    static ble_uuid_t m_adv_uuids[] = 
    {
        {BLE_ADV_UUID, BLE_UUID_TYPE_VENDOR_BEGIN},
    };
    
    // Advertising data structure. This structure contains all options and data needed for encoding and setting the advertising data.
    static ble_advdata_t m_adv_data = 
    {
        .flags                        = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE,
        .uuids_complete.uuid_cnt      = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]),
        .uuids_complete.p_uuids       = m_adv_uuids,
    };
    
    // Options for the different advertisement modes.
    static ble_adv_modes_config_t m_adv_init = 
    {
        .ble_adv_whitelist_enabled      = true,
        .ble_adv_on_disconnect_disabled = true,
        .ble_adv_fast_enabled           = true,
        .ble_adv_fast_interval          = APP_ADV_INTERVAL,
        .ble_adv_fast_timeout           = APP_ADV_DURATION,
    };
    
    // Function for the GAP initialization.
    static void gap_params_init(void)
    {
        ret_code_t    err_code;
        ble_uuid_t    uuid_type;
        ble_uuid128_t base_uuid = {BLE_BASE_UUID};
    
        err_code = sd_ble_uuid_vs_add(&base_uuid, uuid_type);
        APP_ERROR_CHECK(err_code);
    
        return;
    }
    
    // Initialize the advertisement.
    static void advertising_init(void)
    {
        ret_code_t err_code;
        ble_advertising_init_t adv_init;
    
        memset(&adv_init, 0, sizeof(adv_init));
    
        adv_init.advdata     = m_adv_data;
        adv_init.config      = m_adv_init;
        adv_init.evt_handler = on_adv_evt;
    
        err_code = ble_advertising_init(&m_advertising, &adv_init);
        APP_ERROR_CHECK(err_code);
    
        ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
    
        return;
    }

    I checked advertising_init in the SDK's BLE peripheral example, but how do I set the 128-bit base UUID?

    I stopped considering the method of dynamically changing the advertisement payload because the advertisement packet switching was not successful before. However, I will consider it again with reference to the blog you taught me.

    Best regards.

  • Hello,

    sdi_kei said:
    The reason why it was advertised with another UUID was that it was out of the SoftDevice table by that amount because the service and characteristic were set. The problem was solved by adding the number of deviations to "BLE_UUID_TYPE_VENDOR_BEGIN".

    I am not exactly sure about what you mean when you say this, since which UUID is advertised is independent of the SoftDevice table - it only depends on which UUID's you populate the advertising packet with. Perhaps I am misunderstanding you here?

    sdi_kei said:
    Since sd_ble_uuid_vs_add is performed every time advertising_update is called, the number to be added to "BLE_UUID_TYPE_VENDOR_BEGIN" will change. Also, I think that sd_ble_uuid_vs_add will put pressure on the memory space every time. Is there a way to prevent pressure?

    Yes, adding more and more UUID's to the SoftDevice table will eat up the memory over time - you can use the sd_ble_vs_remove function to free this memory as according to the function API.

    sdi_kei said:
    Also, "ble_adv_whitelist_enabled" is set to true in m_adv_init, but I want to be able to select whether to use whitelist or not every time I call advertising_update. Is there a way to choose?

    You may use the ble_advertising_restart_without_whitelist function to restart the current advertising mode without whitelist enabled.
    In general, the 
    ble_advertising_advdata_update function does only update advertising data payload - not the configuration - so if you need to make changes to the advertising configuration you will instead need to stop the advertising, reconfigure, and then restart the advertising.

    sdi_kei said:
    I thought about "ble_advertising_restart_without_whitelist" to temporarily disable it, but how long will this temporary period last? Can it be used for selection?

    The ble_advertising_restart_without_whitelist function will restart the current advertising mode without whitelist, so it will have the same duration / timeout as the advertising mode you are in when this function is called.

    Best regards,
    Karl

  • Hello.

    I am not exactly sure about what you mean when you say this, since which UUID is advertised is independent of the SoftDevice table - it only depends on which UUID's you populate the advertising packet with. Perhaps I am misunderstanding you here?

    Here it means setting the UUID from the SoftDevice table in the advertisement payload.

    I'm using sd_ble_uuid_vs_add to add a UUID to the SoftDevice table.
    However, there is other data in the SoftDevice table, so if you do not specify the added number correctly, you will refer to other data.
    The definition indicating the number is "BLE_UUID_TYPE_VENDOR_BEGIN".
    In my case, it was off by 18, so I was able to correctly set the UUID of the SoftDevice table in the advertisement payload by doing "BLE_UUID_TYPE_VENDOR_BEGIN + 18".

    Yes, adding more and more UUID's to the SoftDevice table will eat up the memory over time - you can use the sd_ble_vs_remove function to free this memory as according to the function API.

    Thank you. Before adding the UUID, I would like to use it to remove the previously added UUID.

    In general, the ble_advertising_advdata_update function does only update advertising data payload - not the configuration - so if you need to make changes to the advertising configuration you will instead need to stop the advertising, reconfigure, and then restart the advertising.

    You can't enable or disable the whitelist at the same time.
    It is possible to disable it with "ble_advertising_restart_without_whitelist", but is there an API to enable it?

    Best regards.

  • Hello,

    sdi_kei said:
    I'm using sd_ble_uuid_vs_add to add a UUID to the SoftDevice table.
    However, there is other data in the SoftDevice table, so if you do not specify the added number correctly, you will refer to other data.
    The definition indicating the number is "BLE_UUID_TYPE_VENDOR_BEGIN".
    In my case, it was off by 18, so I was able to correctly set the UUID of the SoftDevice table in the advertisement payload by doing "BLE_UUID_TYPE_VENDOR_BEGIN + 18".

    Hm.. I am not entirely sure that I follow.. How did you find these offsets?
    The UUID type field is indeed the index relative to BLE_UUID_TYPE_VENDOR_BEGIN like described in the sd_ble_uuid_vs_add API Reference documentation, and it will depend on how many UUID's and other information you have populated the SoftDevice table with already.

    sdi_kei said:
    Thank you. Before adding the UUID, I would like to use it to remove the previously added UUID.

    Great! This should keep your memory from overflowing.

    sdi_kei said:
    You can't enable or disable the whitelist at the same time.
    It is possible to disable it with "ble_advertising_restart_without_whitelist", but is there an API to enable it?

    No, you can not advertise both with and without whitelist - this would effectively mean without whitelist.
    It is also correct that there is no specific function to enable whitelist, instead you can enable whitelist in the advertising configuration p_advertising->adv_modes_config.ble_adv_whitelist_enabled and then restart without whitelist or temporarily disable whitelist if needed.

    Best regards,
    Karl

  • Hello.

    How did you find these offsets?

    I referred to this ticket for the setting method.
    Since "BLE_UUID_TYPE_VENDOR_BEGIN + 1" is set for the second advertisement, I interpreted it as being used in a staggered manner.

    ble_adv_whitelist_enabled and then restart without whitelist or temporarily disable whitelist if needed.

    It was said that the whitelist could not be set, so as you told me, I took the method of stopping it, resetting it, and then starting advertising.

    Best regards.

  • sdi_kei said:
    I referred to this ticket for the setting method.
    Since "BLE_UUID_TYPE_VENDOR_BEGIN + 1" is set for the second advertisement, I interpreted it as being used in a staggered manner.

    Aha, I see - thank you for clarifying.

    sdi_kei said:
    It was said that the whitelist could not be set, so as you told me, I took the method of stopping it, resetting it, and then starting advertising.

    Alright, great - I am glad to hear that this is working as intended now!

    Best regards,
    Karl

Reply
  • sdi_kei said:
    I referred to this ticket for the setting method.
    Since "BLE_UUID_TYPE_VENDOR_BEGIN + 1" is set for the second advertisement, I interpreted it as being used in a staggered manner.

    Aha, I see - thank you for clarifying.

    sdi_kei said:
    It was said that the whitelist could not be set, so as you told me, I took the method of stopping it, resetting it, and then starting advertising.

    Alright, great - I am glad to hear that this is working as intended now!

    Best regards,
    Karl

Children
No Data
Related