hello,
i have one nrf51 dk and it has some advertisement packet, i have another nrf51, i want this another nrf51 to copy first nrf51's data. can you tell me how to copy this advertisement data??
hello,
i have one nrf51 dk and it has some advertisement packet, i have another nrf51, i want this another nrf51 to copy first nrf51's data. can you tell me how to copy this advertisement data??
read the advertisement data from the first one in the second one, set the data in the second one to that, publish it.
i think i should follow ble_app_hrs_c and from where i get scanned packet's data??
Hi,
When the central is scanning, you will get a BLE_GAP_EVT_ADV_REPORT
event each time your device receives an advertisement package. Inside the BLE event handler, on_ble_evt(), you can parse the received package and initialize advertising using the parsed data. I added an example of how this can be done below, to show you the concept. Note that this is not a complete example, and have not been tested.
uint8_t target_address[6] = {0x11,0x22,0x33,0x44,0x55,0x66}
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
const ble_gap_evt_t * p_gap_evt = &p_ble_evt->evt.gap_evt;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_ADV_REPORT:
{
ble_gap_evt_adv_report_t *p_adv_report = &p_gap_evt->params.adv_report;
if(memcmp(target_address, p_adv_report->peer_addr.addr, sizeof(p_adv_report->peer_addr.addr)) == 0)
{
advertising_init(p_adv_report);
}
} break;
}
}
static void advertising_init(ble_gap_evt_adv_report_t *p_adv_report)
{
uint32_t err_code;
ble_advdata_t advdata;
ble_adv_modes_config_t options;
// Build advertising data struct to pass into @ref ble_advertising_init.
memset(&advdata, 0, sizeof(advdata));
// Parse received advertising packet and add to advertising data.
// See central examples for examples of how data is parsed.
memset(&options, 0, sizeof(options));
// Set desired options
err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, NULL);
APP_ERROR_CHECK(err_code);
}
Best regards,
Jørgen