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

BLE Central not getting a scan response message from a sensor

Shalom!

 Our central BLE nrf52840 device continuously scans using a UUID filter. I can see that the UUID is matched in nrf_ble_scan_on_adv_report().  In my ble_evt_handler's BLE_GAP_EVT_ADV_REPORT, I see all BLE devices in the central's range not only my sensor which is OK. I keep a list of the sensors with the filtered UUID and their RSSIs from their advertisements. I can select a MAC and connect to the device from the list without problems.

Now the company want to select a sensor according to its name which is sent in its scan response during he installation process.

I understand that I should be getting two events, one with the p_adv_report->type.scan_response flag raised. The flag is never raised.

Only for product installation, I would like to initiate a scan requests for the sensors, otherwise I would just like to sniff their advertisements.

static ble_gap_scan_params_t const m_scan_param =
{
    .active        = 0x01,
#if (NRF_SD_BLE_API_VERSION > 7)
    .interval_us   = NRF_BLE_SCAN_SCAN_INTERVAL * UNIT_0_625_MS,
    .window_us     = NRF_BLE_SCAN_SCAN_WINDOW * UNIT_0_625_MS,
#else
    .interval      = NRF_BLE_SCAN_SCAN_INTERVAL,
    .window        = NRF_BLE_SCAN_SCAN_WINDOW,
#endif // (NRF_SD_BLE_API_VERSION > 7)
    .filter_policy = BLE_GAP_SCAN_FP_WHITELIST,
    .timeout       = SCAN_DURATION_WITELIST,
    .scan_phys     = BLE_GAP_PHY_1MBPS,
};

/**@brief Function for initializing the scanning and setting the filters.
 */
static void scan_init(bool connect_if_matc)
{
    char sBuf[32];
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;

    memset(&init_scan, 0, sizeof(init_scan));
    init_scan.connect_if_match = connect_if_matc;
    init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;
#ifdef USE_PM
    init_scan.p_scan_param     = &m_scan_param;
#endif

    err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
    APP_ERROR_CHECK(err_code);
    //-------------------------------------------------------------------------
    // Remove any filters previously set
    //-------------------------------------------------------------------------
    err_code = nrf_ble_scan_all_filter_remove(&m_scan);
    APP_ERROR_CHECK(err_code);


    err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &m_ami_uuid);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_UUID_FILTER, true);
    APP_ERROR_CHECK(err_code);
} // scan_init

How can I case a scan request to be sent?

Thank you

David Kaplan

Parents
  • Hello,

    Is the UUID which you are filtering on placed in the adv. packet or in the scan response packet? It looks like .connect_if_match is enabled, so I would expect it to just send a connect request instead of a scan request if you're getting a filter match on the main adv. packet.

    I don't see anything else that's wrong. Maybe you have already, but you can also use the configuration from the ble_app_uart_c example as a reference as it should be similiar to yours (active scanner + uuid filter)

    Best regards,

    Vidar

  • Shalom!

    Thanks for your swift reply.

    I used the app_uart_c example as my base program with the sensors base 128 bit UUID.

    I see that the connect_if_match is disabled and the WireShark sniffing does not show a connection but it does show a scan request and a scan response from the sensor. I am not seeing the response in my event handler's BLE_GAP_EVT_ADV_REPORT as the p_adv_report->type.scan_response flag is never raised. When I want to connect I also set the MAC filter since we may have several sensors and raise the connect_if_match and it does connect.

    Again, most of the time I only want to sniff all sensors updating their RSSIs and want no scan request. In the installation process, I need to get the sensor's name from the scan response and associate it with the sensor's MAC.

    In the BLE_GAP_EVT_ADV_REPORT event I see all kinds of sensors and not just the type for this project. The central is continuously scanning until a connection is warranted to pull or push data.

    I do not currently use a whitelist or encryption.

    #define BLE_UUID_AMI_SERVICE                   0x0101
           
    uint32_t p_ble_maint_c_init(ble_maint_c_t * p_ble_maint_c, ble_maint_c_init_t * p_ble_maint_c_init)
    {
        uint32_t      err_code;
        ble_uuid_t    uart_uuid;
        ble_uuid128_t nus_base_uuid = AMI_BASE_UUID;

        VERIFY_PARAM_NOT_NULL(p_ble_maint_c);
        VERIFY_PARAM_NOT_NULL(p_ble_maint_c_init);
        VERIFY_PARAM_NOT_NULL(p_ble_maint_c_init->p_gatt_queue);

        err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_ble_maint_c->uuid_type);
        VERIFY_SUCCESS(err_code);

        uart_uuid.type = p_ble_maint_c->uuid_type;
        uart_uuid.uuid = BLE_UUID_AMI_SERVICE;

        p_ble_maint_c->conn_handle           = BLE_CONN_HANDLE_INVALID;
        p_ble_maint_c->evt_handler           = p_ble_maint_c_init->evt_handler;
        p_ble_maint_c->error_handler         = p_ble_maint_c_init->error_handler;
        p_ble_maint_c->p_gatt_queue          = p_ble_maint_c_init->p_gatt_queue;

        memset(p_ble_maint_c->maint_db.bl_handle,BLE_GATT_HANDLE_INVALID,sizeof(p_ble_maint_c->maint_db.bl_handle));
        memset(p_ble_maint_c->maint_db.cccd_handle,BLE_GATT_HANDLE_INVALID,sizeof(p_ble_maint_c->maint_db.cccd_handle));
        return ble_db_discovery_evt_register(&uart_uuid);
    } // p_ble_maint_c_init

    Any tips to understand what is happening?

    Thanks

    David Kaplan

Reply
  • Shalom!

    Thanks for your swift reply.

    I used the app_uart_c example as my base program with the sensors base 128 bit UUID.

    I see that the connect_if_match is disabled and the WireShark sniffing does not show a connection but it does show a scan request and a scan response from the sensor. I am not seeing the response in my event handler's BLE_GAP_EVT_ADV_REPORT as the p_adv_report->type.scan_response flag is never raised. When I want to connect I also set the MAC filter since we may have several sensors and raise the connect_if_match and it does connect.

    Again, most of the time I only want to sniff all sensors updating their RSSIs and want no scan request. In the installation process, I need to get the sensor's name from the scan response and associate it with the sensor's MAC.

    In the BLE_GAP_EVT_ADV_REPORT event I see all kinds of sensors and not just the type for this project. The central is continuously scanning until a connection is warranted to pull or push data.

    I do not currently use a whitelist or encryption.

    #define BLE_UUID_AMI_SERVICE                   0x0101
           
    uint32_t p_ble_maint_c_init(ble_maint_c_t * p_ble_maint_c, ble_maint_c_init_t * p_ble_maint_c_init)
    {
        uint32_t      err_code;
        ble_uuid_t    uart_uuid;
        ble_uuid128_t nus_base_uuid = AMI_BASE_UUID;

        VERIFY_PARAM_NOT_NULL(p_ble_maint_c);
        VERIFY_PARAM_NOT_NULL(p_ble_maint_c_init);
        VERIFY_PARAM_NOT_NULL(p_ble_maint_c_init->p_gatt_queue);

        err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_ble_maint_c->uuid_type);
        VERIFY_SUCCESS(err_code);

        uart_uuid.type = p_ble_maint_c->uuid_type;
        uart_uuid.uuid = BLE_UUID_AMI_SERVICE;

        p_ble_maint_c->conn_handle           = BLE_CONN_HANDLE_INVALID;
        p_ble_maint_c->evt_handler           = p_ble_maint_c_init->evt_handler;
        p_ble_maint_c->error_handler         = p_ble_maint_c_init->error_handler;
        p_ble_maint_c->p_gatt_queue          = p_ble_maint_c_init->p_gatt_queue;

        memset(p_ble_maint_c->maint_db.bl_handle,BLE_GATT_HANDLE_INVALID,sizeof(p_ble_maint_c->maint_db.bl_handle));
        memset(p_ble_maint_c->maint_db.cccd_handle,BLE_GATT_HANDLE_INVALID,sizeof(p_ble_maint_c->maint_db.cccd_handle));
        return ble_db_discovery_evt_register(&uart_uuid);
    } // p_ble_maint_c_init

    Any tips to understand what is happening?

    Thanks

    David Kaplan

Children
Related