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

Reply
  • 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

Children
  • 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.

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

    I am not sure what you are asking me about here - would you like the advertising payload to contain the custom UUID?
    If so, you may do so as demonstrated in the BLE app uart example - which is close to what you are doing currently.

    sdi_kei said:
    However, I will consider it again with reference to the blog you taught me.

    Great, I am happy to hear that you found the blogpost useful! :)
    At the very end of the blogpost there is also a minimal example that shows how you could perform dynamic updates of the advertising payload.

    Best regards,
    Karl

  • I am not sure what you are asking me about here

    The explanation was insufficient. I'm sorry.
    I only know how to set a 128bit UUID is sd_ble_uuid_vs_add. I checked the SDK's advertising_init, but I couldn't figure out how to set the 128bit UUID. I would like to know how to set it.

    At the very end of the blogpost there is also a minimal example that shows how you could perform dynamic updates of the advertising payload.

    It is ble_app_update_advertising_data.zip, but when I tried to start it with IAR Embedded Workbench, "Could not open the project" was displayed and I could not confirm the operation.

    Best regards.

  • sdi_kei said:
    The explanation was insufficient. I'm sorry.

    No need to apologize, I am just trying to understand your issue better so that I may provide you better help resolving it.

    sdi_kei said:
    I only know how to set a 128bit UUID is sd_ble_uuid_vs_add. I checked the SDK's advertising_init, but I couldn't figure out how to set the 128bit UUID. I would like to know how to set it.

    The sd_ble_uuid_vs_add is the function for adding the UUID as a base UUID in the SoftDevice. However, this does not have anything to do with the advertising directly.
    Adding datafields to the advertising data payload is not the same as adding UUIDs the SoftDevice table.
    Could you elaborate what you mean when you say that you would like to 'set it'?
    If you mean that you would like to add the UUID to your advertising data payload, then you should do it as demonstrated in the ble app uart example.

    sdi_kei said:
    It is ble_app_update_advertising_data.zip, but when I tried to start it with IAR Embedded Workbench, "Could not open the project" was displayed and I could not confirm the operation.

    Oh, I was not aware that you were using IAR.
    The example is a SES project, however you could still see how the dynamic advertising data update is done by looking at the main.c file in the project.

    Best regards,
    Karl

  • Hello.

    Could you elaborate what you mean when you say that you would like to 'set it'?

    I don't understand what is shown in the uart example of the ble app, so please tell me what it is.

    Use sd_ble_uuid_vs_add to add a 128bit base UUID to your soft device. This base UUID is linked by setting BLE_UUID_TYPE_VENDOR_BEGIN in m_adv_uuids. The base UUID is used by setting this m_adv_uuids to uuids_complete.p_uuids.

    I have interpreted the 128-bit base UUID in my own way, but is it correct?

    The example is a SES project, however you could still see how the dynamic advertising data update is done by looking at the main.c file in the project.

    I'm checking how to update the dynamic advertisement data and creating a process, but if I dynamically set m_adv_uuids to uuids_complete.p_uuids, it will be advertised with a different base UUID.
    I don't know why something like that happens.
    Please let me know if you know.

    Best regards.

Related