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 Reply Children
  • 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().

Related