ble advertizing data update dynamically in the prigram

Hi

I want to update the ble advertising data in my program. In nrf5340 the bt_le_adv_start() command should run only once in the main program.

Is it possible to change the advertising data of ble device in broadcast non connectable mode by bt_data_bytes() or bt_data() commands or

any other means. Its also preferable to use extended mode to be able to use 256 bytes of data while broadcasting.

Thank you in advance for your support.

Best regards.

Parents
  • Hello,

    I have not tested it yet, but there is a function called bt_le_adv_update_data(). I am not sure whether you need to stop the adverting using bt_le_adv_stop() before updating the data or not. Check the return value from bt_le_adv_update to see whether it succeeds without stopping the advertising data.

    Best regards,

    Edvin

  • Hi

    I have tested it on my custom board. It worked without the need of using bt_le_adv_stop().

    But I have another question yet. I want to use the ble radio in extended mode to be able to

    transfer more than just 32 bytes.

    Again thank you for your supports.

    Best regards,

    Saeed

  • You can ad a scan response packet in bt_le_adv_start():

    int bt_le_adv_start(const struct bt_le_adv_param *param,
    		    const struct bt_data *ad, size_t ad_len,
    		    const struct bt_data *sd, size_t sd_len);

    The parameters *sd and sd_len is the scan response data, which gives you another 31 bytes. If you need even more, then you need to look into bt_le_ext_adv_create(). In fact, you will find a lot of the possibilities by looking at the bluetooth.h file found in NCS\zephyr\include\bluetooth\bluetooth.h.

    Best regards,

    Edvin

  • Hi

    Thank you very much for your guidance. But let me discus another question.

    Actually I want to attach the serial port receiving data to ad area field of my advertising device. Should

    I use BT_DATA_BYTES()? As far as I tried only static constant data can be used in this function.

    How could I change the ad data dynamically in the program.?

  • In order to write completely custom data, I suggest you look into something called manufacturer specific data:

    static uint8_t adv_array[4] = {0};
    
    static const struct bt_data ad[] = {
        BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
        BT_DATA(BT_DATA_MANUFACTURER_DATA, adv_array, sizeof(adv_array)),
    }

    The size can be larger than 4 bytes.

    However, updating the adv_array directly wouldn't change the advertisements. You still need to update the advertising data with the updated adv_array whenever you want to update the advertisements.

    BR,

    Edvin

  • Hi

    Thank you very much. I have tested it and it did work.

  • Hi again

    Would you please to explain a little more about bt_le_ext_adv_create() usage. Should I still use these lines:

    static uint8_t adv_array[29] = {0};

    static const struct bt_data ad[] = {
    BT_DATA(BT_DATA_BIG_INFO, adv_array, sizeof(adv_array)),
    };

    // Set Scan Response data //
    static const struct bt_data sd[] = {
    BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
    };

    and

    bt_enable(NULL);
    bt_le_adv_start(BT_LE_ADV_NCONN_IDENTITY, ad, ARRAY_SIZE(ad),0,0);

    or I should completely change them and define new struct variables compatible with bt_le_ext_adv_create().

Reply
  • Hi again

    Would you please to explain a little more about bt_le_ext_adv_create() usage. Should I still use these lines:

    static uint8_t adv_array[29] = {0};

    static const struct bt_data ad[] = {
    BT_DATA(BT_DATA_BIG_INFO, adv_array, sizeof(adv_array)),
    };

    // Set Scan Response data //
    static const struct bt_data sd[] = {
    BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
    };

    and

    bt_enable(NULL);
    bt_le_adv_start(BT_LE_ADV_NCONN_IDENTITY, ad, ARRAY_SIZE(ad),0,0);

    or I should completely change them and define new struct variables compatible with bt_le_ext_adv_create().

Children
  • Hello,

    saeed mahvis said:
    or I should completely change them and define new struct variables compatible with bt_le_ext_adv_create()

    Disclaimer: I have not used the extended advertisements. Check the input parameters.

    Well... With the snippet above, first of all, you are not using sd anywhere, just so you know.

    Is there a reason you are using BT_DATA_BIG_INFO? Do you know what it refers to, or did you just take it because it contains the name "BIG"?

    If you don't know what it is (I don't), I suggest you stick with the BT_DATA_MANUFACTURER_DATA, which is a field where you can use completely custom data. That may not be the case in "BT_DATA_BIG_INFO".

    BR,

    Edvin

  • The BT_DATA_BIG_INFO macro in the nRF Connect SDK is used to define a Bluetooth advertising data structure for broadcasting information about a Broadcast Isochronous Group (BIG). This is part of the Bluetooth LE Audio features, which allow for synchronized audio streaming to multiple devices.

Related