Hi,
I'm using the S132 v6.0 and SDK v15.0 to work with nRF52832. I found the it just get the advertising data. If the device put some data into the scan response, when I use 52832 to scan, how to get the scan response data? Thanks.
Hi,
I'm using the S132 v6.0 and SDK v15.0 to work with nRF52832. I found the it just get the advertising data. If the device put some data into the scan response, when I use 52832 to scan, how to get the scan response data? Thanks.
Hi,
You have to do active scanning in order to get the scan response. To do that, simply set the active field of the ble_gap_scan_params_t instance to 1 before you pass it in the call to sd_ble_gap_scan_start(). Then you will get the scan response data in a BLE_GAP_EVT_ADV_REPORT event in the same way as you get normal advertising data. You can see which type it is by checking the type field in the ble_gap_evt_adv_report_t.
Does S132v6.0 could do it? I have set the active field of the ble_gap_scan_params_t instance to 1, but I couldn't get the scan response data. The bit scan_response of ble_gap_adv_report_type_t is always 0.
Does S132v6.0 could do it? I have set the active field of the ble_gap_scan_params_t instance to 1, but I couldn't get the scan response data. The bit scan_response of ble_gap_adv_report_type_t is always 0.
That's strange. Have you made sure to configure the peripheral so that it has scan response data (essentially just populate ble_advertising_init_t::srdata)?
Yes, I'm sure about it.
You should not have to do anything more. Can you upload the code for your advertiser and scanner?
static void advertising_init(void) { uint32_t err_code; ble_advertising_init_t init; uint8_t m_addl_adv_manuf_data[19] = {0xaa,0xbb,0x00,0x00,0xC4,0xF1,0x00,0x0b,0x03,0x01}; memset(&init, 0, sizeof(init)); ble_advdata_manuf_data_t manuf_data; manuf_data.data.size = sizeof(m_addl_adv_manuf_data); manuf_data.data.p_data = &m_addl_adv_manuf_data[2]; init.advdata.p_manuf_specific_data = &manuf_data; init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; init.srdata.name_type = BLE_ADVDATA_FULL_NAME; init.srdata.include_appearance = false; init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]); init.srdata.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; 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); } ble_gap_scan_params_t const m_scan_params = { .active = 1, .interval = SCAN_INTERVAL, .window = SCAN_WINDOW, .timeout = SCAN_DURATION, .scan_phys = BLE_GAP_PHY_1MBPS, .filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL, }; void on_adv_report(ble_gap_evt_adv_report_t const * p_adv_report) { printf("scan_response=%04x\r\n",p_adv_report->type); printf("%02x %02x %02x %02x %02x %02x\r\n",p_adv_report->peer_addr.addr[5], p_adv_report->peer_addr.addr[4],p_adv_report->peer_addr.addr[3], p_adv_report->peer_addr.addr[2],p_adv_report->peer_addr.addr[1], p_adv_report->peer_addr.addr[0]); if(p_adv_report->peer_addr.addr[5]==0xDE&&p_adv_report->peer_addr.addr[4]==0x88) { printf("ADV data:\r\n"); for(uint8_t i=0;i<p_adv_report->data.len;i++) printf("%02x ",p_adv_report->data.p_data[i]); printf("\r\n"); } uint32_t ret = sd_ble_gap_scan_start(&m_scan_params, &m_scan_buffer); }
This is the code for the ble_advertising_init and the scan report.
I don't see any problems with your code, neither the scanner nor the advertiser.
For reference (and if you would like to test with a known working example), I stripped down a central project to only do active scanning and logging whether an advertisement packet or scan response packet was received. The two relevant functions are here:
static void scan_start(void) { ret_code_t ret; m_scan_param.active = 1; m_scan_param.interval = SCAN_INTERVAL; m_scan_param.window = SCAN_WINDOW; m_scan_param.timeout = SCAN_DURATION; m_scan_param.scan_phys = BLE_GAP_PHY_1MBPS; m_scan_param.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL; ret = sd_ble_gap_scan_start(&m_scan_param, &m_scan_buffer); APP_ERROR_CHECK(ret); }
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context) { ret_code_t err_code; ble_gap_evt_adv_report_t const * p_adv_report = &p_ble_evt->evt.gap_evt.params.adv_report; switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_ADV_REPORT: if (p_adv_report->type.scan_response) { if (p_adv_report->data.len > 0) { NRF_LOG_INFO("Scan response received:"); NRF_LOG_RAW_HEXDUMP_INFO(p_adv_report->data.p_data, p_adv_report->data.len); } else { NRF_LOG_INFO("Empty scan response received."); } } else { NRF_LOG_INFO("Advertising packet received:"); NRF_LOG_RAW_HEXDUMP_INFO(p_adv_report->data.p_data, p_adv_report->data.len); } // Continue scanning. sd_ble_gap_scan_start(NULL, &m_scan_buffer); break; default: break; } }
Here are full projects for SDK 15.0 (ble_active_scanner_sdk_15.0.zip) and SDK 15.2 (ble_active_scanner_sdk__15.2.zip).