This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Can I put measured data in the Scan Response packet?

I'm looking at an application where it would be beneficial to be able to read data from the bluetooth device as it passes. It would be easiest for me to do this by simply reading the scan response data if it was possible to put the measured data in there somehow.

Is this possible? It seems in the examples the scan response packet is set when he advertising is initialised, so can I change it afterwards?

My existing advertising initialisation is this:

static void advertising_init(void)
{
    uint32_t      err_code;
    ble_advdata_t advdata;

    // Build advertising data struct to pass into ble_advertising_init().
    memset(&advdata, 0, sizeof(advdata));

    advdata.name_type               = BLE_ADVDATA_FULL_NAME;
    advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

    ble_adv_modes_config_t options = {0};
    options.ble_adv_fast_enabled  = BLE_ADV_FAST_ENABLED;
    options.ble_adv_fast_interval = APP_ADV_INTERVAL;
    options.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;
    
    // Create a scan response packet and include the list of UUIDs 
	ble_uuid_t m_adv_uuids[] = {BLE_UUID_OUR_SERVICE, BLE_UUID_TYPE_VENDOR_BEGIN};
	
	ble_advdata_t sr_data;
	memset(&sr_data, 0, sizeof(sr_data));
	
	sr_data.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
	sr_data.uuids_complete.p_uuids = m_adv_uuids;

	err_code = ble_advertising_init(&advdata, &sr_data, &options, on_adv_evt, NULL);
    APP_ERROR_CHECK(err_code);
}
Parents
  • Change it whenever you want, change the advertising data or the scan data or both of them. Just set it and the next advertisement will go out with the new data.

    I use manufacturer data to transmit basic state on my device, including when it's in connection (just make the advertising non-connectable). It's easy.

  • no you don't just update the variable, you actually have to set it into the softdevice, it doesn't keep a reference to it, it copies it. sd_ble_gap_adv_data_set() is the function which actually sets the binary advertising data which actually goes out over the air.

    And for non-connectable, there's a flag for advertising type. If you're using the advertising module, which I don't, you'll have to look through the code for that to see what it's calling. I suspect that module has a mode where it advertises connectable when there's no connection and non-connectable when in connection, if you get it into that mode it'll start and stop the adverts for you, you just need to encode and set the data.

Reply
  • no you don't just update the variable, you actually have to set it into the softdevice, it doesn't keep a reference to it, it copies it. sd_ble_gap_adv_data_set() is the function which actually sets the binary advertising data which actually goes out over the air.

    And for non-connectable, there's a flag for advertising type. If you're using the advertising module, which I don't, you'll have to look through the code for that to see what it's calling. I suspect that module has a mode where it advertises connectable when there's no connection and non-connectable when in connection, if you get it into that mode it'll start and stop the adverts for you, you just need to encode and set the data.

Children
No Data
Related