Change advertisement from connectable to non-connectable and changing advdata dynamically

https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-advertising-a-beginners-tutorial

I am starting with this tutorial. I want to program the nrf52840 with a sensor. After I retrieve the data, I hope that I can place the data into the data field.

But how do I update the data field? Should I just change the value of the manuf_data in the for loop in the main function?

Hence, and I would like to ask how do I change the advertisement packet from connectable to non-connectable?

static void advertising_init(void)
{
    ret_code_t             err_code;
    ble_advertising_init_t init;  // Struct containing advertising parameters
    // Build advertising data struct to pass into @ref ble_advertising_init.
    memset(&init, 0, sizeof(init));

    ble_advdata_manuf_data_t                  manuf_data; //Variable to hold manufacturer specific data
    uint8_t data[]                            = "SomeData!"; //Our data to advertise
    manuf_data.company_identifier             =  0x0059; //Nordics company ID
    manuf_data.data.p_data                    = data;
    manuf_data.data.size                      = sizeof(data);
    init.advdata.p_manuf_specific_data = &manuf_data;

    init.advdata.name_type = BLE_ADVDATA_FULL_NAME; // Use a shortened name
    init.advdata.short_name_len = 6; // Advertise only first 6 letters of name
    init.advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.advdata.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(&m_advertising, &init);
    APP_ERROR_CHECK(err_code);

    ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
}

Related