Environment
- Platform: Windows 7
- IDE: SEGGER Embedded Studio for ARM V5.42a (64bit)
- SDK: clean nRF5_SDK_17.1.0
- Project: usbd_ble_uart_c_v4 and modify with usbd function
- SoftDevice: s140_nrf52_7.2.0_softdevice.hex
- Terminal: PuTTy (COM7 , baud rate 115200)
Purpose/ Question
Hi everybody. I want to scan and print the address of advertising data to serial port on 52840 dongle. I set the scan filter (UUID/ ADDR/ NAME/ SHORT NAME) and
print the address in case BLE_GAP_EVT_ADV_REPORT of ble_evt_handler, and then it prints the fixed direct_addr/ peer_addr and fixed peer_addr.addr_id_peer continually
on the terminal. How can I solve it? Thank you.
Code
- Scan part of sdk_config.h
// <e> NRF_BLE_SCAN_FILTER_ENABLE - Enabling filters for the Scanning Module. //========================================================== #ifndef NRF_BLE_SCAN_FILTER_ENABLE #define NRF_BLE_SCAN_FILTER_ENABLE 1 #endif // <o> NRF_BLE_SCAN_UUID_CNT - Number of filters for UUIDs. #ifndef NRF_BLE_SCAN_UUID_CNT #define NRF_BLE_SCAN_UUID_CNT 0 // v0.02 #endif // <o> NRF_BLE_SCAN_NAME_CNT - Number of name filters. #ifndef NRF_BLE_SCAN_NAME_CNT #define NRF_BLE_SCAN_NAME_CNT 0 // v0.02 #endif // <o> NRF_BLE_SCAN_SHORT_NAME_CNT - Number of short name filters. #ifndef NRF_BLE_SCAN_SHORT_NAME_CNT #define NRF_BLE_SCAN_SHORT_NAME_CNT 1 #endif // <o> NRF_BLE_SCAN_ADDRESS_CNT - Number of address filters. #ifndef NRF_BLE_SCAN_ADDRESS_CNT #define NRF_BLE_SCAN_ADDRESS_CNT 0 // v0.02 #endif // <o> NRF_BLE_SCAN_APPEARANCE_CNT - Number of appearance filters. #ifndef NRF_BLE_SCAN_APPEARANCE_CNT #define NRF_BLE_SCAN_APPEARANCE_CNT 0 #endif
- scan_init(void)
static void scan_init(void) { ret_code_t err_code; nrf_ble_scan_init_t init_scan; memset(&init_scan, 0, sizeof(init_scan)); init_scan.connect_if_match = false; init_scan.conn_cfg_tag = APP_BLE_CONN_CFG_TAG; err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler); APP_ERROR_CHECK(err_code); /* v0.02 change from 'SCAN_UUID_FILTER' to 'SCAN_ADDR_FILTER' err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_ADDR_FILTER, m_target_periph.addr); APP_ERROR_CHECK(err_code); err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_ADDR_FILTER, false); APP_ERROR_CHECK(err_code); */ err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_SHORT_NAME_FILTER, m_target_periph_name); APP_ERROR_CHECK(err_code); err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_SHORT_NAME_FILTER, false); APP_ERROR_CHECK(err_code); } - case BLE_GAP_EVT_ADV_REPORT of ble_evt_handler
case BLE_GAP_EVT_ADV_REPORT: { size_t size; ret_code_t ret; size = sprintf(m_test_buffer, "PEER_ADDR:%x\r\n", p_gap_evt->params.adv_report.peer_addr.addr); ret = app_usbd_cdc_acm_write(&m_app_cdc_acm, m_test_buffer, size); //size = sprintf(m_test_buffer, "DIRECT_ADDR:%s\r\n", p_gap_evt->params.adv_report.direct_addr.addr); //ret = app_usbd_cdc_acm_write(&m_app_cdc_acm, m_test_buffer, size); } break; - Result on terminal