Ble_scan.h header file is not found while I`m working on the code below I`m searching for BLE scan code for nearby devices on PCA10040e board.

#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "app_error.h"
#include "ble_scan.h"
#include "ble_gap.h"

#define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */
#define APP_BLE_OBSERVER_PRIO 3 /**< Application's BLE observer priority. You shouldn't need to modify this value. */

#define SCAN_WINDOW 15000 /**< Scan window duration in milliseconds. */
#define SCAN_INTERVAL 12000 /**< Scan interval duration in milliseconds. */
#define SCAN_TIMEOUT 120000 /**< Scan timeout duration in milliseconds. */

#define SCAN_BUFFER_SIZE 10 /**< Maximum number of scan results to buffer. */

NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_scan_init, NULL);

static ble_scan_t m_scan;

static ble_gap_scan_params_t const m_scan_params =
{
.active = 1,
.interval = SCAN_INTERVAL,
.window = SCAN_WINDOW,
.timeout = SCAN_TIMEOUT,
.scan_phys = BLE_GAP_PHY_1MBPS,
.buffer = {SCAN_BUFFER_SIZE, 0},
};

/**@brief Scan event handler.
*
* @param[in] p_scan_evt Scan event.
*/
static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{
switch (p_scan_evt->scan_evt_id)
{
case NRF_BLE_SCAN_EVT_CONNECTING_ERROR:
// Error while connecting to peer.
break;

case NRF_BLE_SCAN_EVT_SCAN_TIMEOUT:
// The scan has timed out.
break;

case NRF_BLE_SCAN_EVT_FILTER_MATCH:
{
// A device has been found that matches the filter criteria.
// Extract the advertising report from the event.
nrf_ble_scan_evt_filter_match_t * p_filter_match = &p_scan_evt->data.filter_match;
nrf_ble_scan_evt_filter_match_t filter_match = *p_filter_match;

// Extract the advertising data from the report.
ble_gap_evt_adv_report_t * p_adv_report = &filter_match.p_adv_report;

// Check if the found device is the desired device.
if (is_desired_device(p_adv_report))
{
// The desired device has been found.
// Extract the MAC address of the device.
ble_gap_addr_t gap_address = p_adv_report->peer_addr;

// Print the MAC address of the device.
printf("MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
gap_address.addr[0], gap_address.addr[1], gap_address.addr[2],
gap_address.addr[3], gap_address.addr[4], gap_address.addr[5]);

// Print the RSSI value of the device.
printf("RSSI value: %d\n", p_adv_report->rssi);
}
break;
}
/**@brief Initialize the BLE scan module.
*/
void ble_scan_init(void)
{
ret_code_t err_code;

err_code = ble_scan_init(&m_scan, &m_scan_params, scan_evt_handler);
APP_ERROR_CHECK(err_code);
}

int main(void)
{
ret_code_t err_code = nrf_sdh_enable_request();
APP_ERROR_CHECK(err_code);

// Configure the BLE stack using the default settings.
// Fetch the start address of the application RAM.
uint32_t ram_start = 0;
err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
APP_ERROR_CHECK(err_code);

// Enable BLE stack.
err_code = nrf_sdh_ble_enable(&ram_start);
APP_ERROR_CHECK(err_code);

// Start BLE scanning.
err_code = ble_scan_start(&m_scan);
APP_ERROR_CHECK(err_code);

// Enter main loop.
for (;;)
{
// Wait for an event.
}
}   

Parents
  • Hi,

    If the compiler does not find the header file it means it is not in the include path. There is no ble_scan.h file in the SDK, though. Did you mean nrf_ble_scan.h? This is for the module (components/ble/nrf_ble_scan/).

    Also, remember that in order to scan you need to use a SoftDevice that supports the central role. See the overview of the SoftDevices.

  • Thanks Einer for answering, Basically the problem is that while I`m working on this code . There is no such example for BLE Scanning present in the examples and then when I switched to nrf_ble_scan.h . The Header source file are showing errors like this is my modified code - 

    #include <stdbool.h>
    #include <stdint.h>
    #include "nrf.h"
    #include "nordic_common.h"
    #include "nrf_gpio.h"
    #include "boards.h"
    #include "nrf_ble_scan.h"
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    #include "nrf_delay.h"
    #include "nrf_drv_rtc.h"
    #include "nrf_drv_clock.h"
    #include "nrf_drv_gpiote.h"
    #include "nrfx_saadc.h"
    #include "nrfx_ppi.h"
    #include "nrfx_timer.h"
    #include "nrfx_ppi.h"
    #include "nrfx_uarte.h"
    #include "nrfx_prs.h"

    #define SCAN_INTERVAL 0x00A0 // Determines scan interval in units of 0.625 millisecond.
    #define SCAN_WINDOW 0x0050 // Determines scan window in units of 0.625 millisecond.
    #define SCAN_TIMEOUT 0 // Timout when scanning. 0 means no timeout.

    #define APP_BLE_CONN_CFG_TAG 1 // A tag identifying the SoftDevice BLE configuration.

    NRF_BLE_SCAN_DEF(m_scan); // Scan module instance.

    static uint32_t ble_counter = 0; // Counter for the number of BLE devices found.

    /**
    * @brief Function for handling the BLE scan events.
    */
    static void scan_evt_handler(scan_evt_t const * p_scan_evt)
    {
    switch (p_scan_evt->scan_evt_id)
    {
    case NRF_BLE_SCAN_EVT_SCAN_TIMEOUT:
    NRF_LOG_INFO("Scan timed out.");
    break;

    case NRF_BLE_SCAN_EVT_FILTER_MATCH:
    NRF_LOG_INFO("BLE device found! Address: 0x%x", p_scan_evt->params.filter_match.p_adv_report->peer_addr.addr[0]);
    ble_counter++;
    break;

    case NRF_BLE_SCAN_EVT_NOT_FOUND:
    NRF_LOG_INFO("No BLE device found that matches the scan filter.");
    break;

    default:
    // No implementation needed.
    break;
    }
    }

    /**
    * @brief Function for initializing the BLE scan module.
    */
    static void ble_scan_init(void)
    {
    ret_code_t err_code;

    nrf_ble_scan_init_t scan_init = {
    .scan_param = {
    .interval = SCAN_INTERVAL,
    .window = SCAN_WINDOW,
    .timeout = SCAN_TIMEOUT,
    .active = 1
    },
    .connect_if_match = false,
    .scan_evt_handler = scan_evt_handler
    };

    err_code = nrf_ble_scan_init(&m_scan, &scan_init);
    APP_ERROR_CHECK(err_code);
    }

    /**
    * @brief Function for starting the BLE scan module.
    */
    static void ble_scan_start(void)
    {
    ret_code_t err_code;

    err_code = nrf_ble_scan_start(&m_scan);
    APP_ERROR_CHECK(err_code);
    }

    int main(void)
    {
    ret_code_t err_code;

    // Initialize logging.
    err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    // Initialize the BLE stack.
    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);

    // Initialize the BLE scan module.
    nrf_ble_scan_init_t scan_init = {
    .scan_param = {
    .interval = SCAN_INTERVAL,
    .window = SCAN_WINDOW,
    .timeout = SCAN_TIMEOUT,
    .active = 1
    },
    .connect_if_match = false,
    .evt_handler = scan_evt_handler
    };
    err_code = nrf_ble_scan_init(&m_scan, &scan_init);
    APP_ERROR_CHECK(err_code);

    // Start scanning for nearby BLE devices.
    err_code = nrf_ble_scan_start(&m_scan);
    APP_ERROR_CHECK(err_code);

    while (true)
    {
    NRF_LOG_FLUSH();
    nrf_delay_ms(10);
    }
    }                                                              

    And the errors I`m getting in the nrf_ble_scan.h file associated with my code =            Rebuilding ‘ble_app_hrs_pca10040e_s112’ from solution ‘ble_app_hrs_pca10040e_s112’ in configuration ‘Release’
    Assembling ‘thumb_crt0.s’
    Compiling ‘bsp.c’
    Compiling ‘bsp_btn_ble.c’
    Compiling ‘nrf_hw_backend_init.c’
    Compiling ‘nrf_hw_backend_rng.c’
    Compiling ‘nrf_hw_backend_rng_mbedtls.c’
    Compiling ‘app_button.c’
    Compiling ‘app_error.c’
    Compiling ‘app_error_handler_gcc.c’
    Compiling ‘app_error_weak.c’
    Compiling ‘app_scheduler.c’
    Compiling ‘app_timer2.c’
    Compiling ‘app_util_platform.c’
    Compiling ‘crc16.c’
    Compiling ‘drv_rtc.c’
    Compiling ‘fds.c’
    Compiling ‘hardfault_implementation.c’
    Compiling ‘mem_manager.c’
    Compiling ‘nrf_assert.c’
    Compiling ‘nrf_atfifo.c’
    Compiling ‘nrf_atflags.c’
    Compiling ‘nrf_atomic.c’
    Compiling ‘nrf_balloc.c’
    Compiling ‘nrf_fprintf.c’
    Compiling ‘nrf_fprintf_format.c’
    Compiling ‘nrf_fstorage.c’
    Compiling ‘nrf_fstorage_sd.c’
    Compiling ‘nrf_memobj.c’
    Compiling ‘nrf_pwr_mgmt.c’
    Compiling ‘nrf_queue.c’
    Compiling ‘nrf_ringbuf.c’
    Compiling ‘nrf_section_iter.c’
    Compiling ‘nrf_sortlist.c’
    Compiling ‘nrf_strerror.c’
    Compiling ‘sensorsim.c’
    Compiling ‘nrf_drv_clock.c’
    Compiling ‘nrf_drv_rng.c’
    Compiling ‘nrf_drv_uart.c’
    Compiling ‘nrfx_atomic.c’
    Compiling ‘nrfx_clock.c’
    Compiling ‘nrfx_gpiote.c’
    Compiling ‘nrfx_prs.c’
    Compiling ‘nrfx_rng.c’
    Compiling ‘nrfx_uart.c’
    Compiling ‘nrfx_uarte.c’
    Compiling ‘boards.c’
    Compiling ‘nrf_log_backend_rtt.c’
    Compiling ‘nrf_log_backend_serial.c’
    Compiling ‘nrf_log_backend_uart.c’
    Compiling ‘nrf_log_default_backends.c’
    Compiling ‘nrf_log_frontend.c’
    Compiling ‘nrf_log_str_formatter.c’
    Compiling ‘aes.c’
    Compiling ‘ctr_drbg.c’
    Compiling ‘platform_util.c’
    Compiling ‘nrf_crypto_aead.c’
    Compiling ‘nrf_crypto_aes.c’
    Compiling ‘nrf_crypto_aes_shared.c’
    Compiling ‘nrf_crypto_ecc.c’
    Compiling ‘nrf_crypto_ecdh.c’
    Compiling ‘nrf_crypto_ecdsa.c’
    Compiling ‘nrf_crypto_eddsa.c’
    Compiling ‘nrf_crypto_error.c’
    Compiling ‘nrf_crypto_hash.c’
    Compiling ‘nrf_crypto_hkdf.c’
    Compiling ‘nrf_crypto_hmac.c’
    Compiling ‘nrf_crypto_init.c’
    Compiling ‘nrf_crypto_rng.c’
    Compiling ‘nrf_crypto_shared.c’
    Compiling ‘main.c’
    main.c
    expected specifier-qualifier-list before 'ble_gap_scan_params_t'
    expected specifier-qualifier-list before 'ble_gap_evt_adv_report_t'
    expected specifier-qualifier-list before 'ble_gap_evt_adv_report_t'
    expected specifier-qualifier-list before 'ble_gap_scan_params_t'
    unknown type name 'ble_gap_scan_params_t'
    'NRF_BLE_SCAN_BUFFER' undeclared here (not in a function); did you mean 'NRF_BLE_SCAN_DEF'?
    unknown type name 'ble_gap_scan_params_t'; did you mean 'ble_gap_sec_params_t'?
    app_pwm.h
    nrf_timer.h
    nrfx_timer.h
    main.c
    unknown type name 'nrfx_timer_t'
    unknown type name 'nrfx_timer_config_t'
    implicit declaration of function 'NRFX_TIMER_INSTANCE'; did you mean 'NRF_DRV_TIMER_INSTANCE'? [-Wimplicit-function-declaration]
    in expansion of macro 'NRF_DRV_TIMER_INSTANCE'
    in expansion of macro 'APP_PWM_INSTANCE'
    initializer element is not constant
    in expansion of macro 'NRF_DRV_TIMER_INSTANCE'
    in expansion of macro 'APP_PWM_INSTANCE'
    main.c
    unknown type name 'nrf_timer_frequency_t'
    unknown type name 'nrf_timer_mode_t'
    unknown type name 'nrf_timer_bit_width_t'
    unknown type name 'nrf_timer_event_t'; did you mean 'nrf_saadc_event_t'?
    unknown type name 'nrfx_timer_event_handler_t'; did you mean 'nrf_timer_event_handler_t'?
    unknown type name 'nrf_timer_task_t'; did you mean 'nrf_ppi_task_t'?
    unknown type name 'nrf_timer_event_t'; did you mean 'nrf_saadc_event_t'?
    unknown type name 'nrf_timer_cc_channel_t'; did you mean 'nrf_ppi_channel_t'?
    unknown type name 'nrf_timer_cc_channel_t'; did you mean 'nrf_ppi_channel_t'?
    unknown type name 'nrf_timer_cc_channel_t'; did you mean 'nrf_ppi_channel_t'?
    unknown type name 'nrf_timer_cc_channel_t'; did you mean 'nrf_ppi_channel_t'?
    unknown type name 'nrf_timer_short_mask_t'
    unknown type name 'nrf_timer_task_t'; did you mean 'nrf_ppi_task_t'?
    implicit declaration of function 'nrf_timer_task_address_get'; did you mean 'nrf_drv_timer_task_address_get'? [-Wimplicit-function-declaration]
    implicit declaration of function 'nrf_timer_capture_task_get'; did you mean 'nrfx_timer_capture_task_address_get'? [-Wimplicit-function-declaration]
    unknown type name 'nrf_timer_event_t'; did you mean 'nrf_saadc_event_t'?
    implicit declaration of function 'nrf_timer_event_address_get'; did you mean 'nrf_drv_timer_event_address_get'? [-Wimplicit-function-declaration]
    implicit declaration of function 'nrf_timer_compare_event_get'; did you mean 'nrf_rtc_compare_event_get'? [-Wimplicit-function-declaration]
    unknown type name 'nrf_timer_cc_channel_t'; did you mean 'nrf_ppi_channel_t'?
    implicit declaration of function 'nrf_timer_us_to_ticks'; did you mean 'nrfx_timer_us_to_ticks'? [-Wimplicit-function-declaration]
    implicit declaration of function 'nrf_timer_frequency_get' [-Wimplicit-function-declaration]
    implicit declaration of function 'nrf_timer_ms_to_ticks'; did you mean 'nrfx_timer_ms_to_ticks'? [-Wimplicit-function-declaration]
    nrfx_config.h
    nrfx.h
    nrf_gpio.h
    main.c
    expected ')' before numeric constant
    in expansion of macro 'NRF_BLE_SCAN_OBSERVER_PRIO'
    in expansion of macro 'NRF_BLE_SCAN_DEF'
    nrf_log.h
    main.c
    'nrf_ble_scan_evt_filter_match_t' has no member named 'p_adv_report'
    in definition of macro 'LOG_INTERNAL_1'
    in expansion of macro 'LOG_INTERNAL_X'
    in expansion of macro 'LOG_INTERNAL'
    in expansion of macro 'NRF_LOG_INTERNAL_MODULE'
    in expansion of macro 'NRF_LOG_INTERNAL_INFO'
    in expansion of macro 'NRF_LOG_INFO'
    'nrf_ble_scan_init_t' has no member named 'scan_param'
    extra brace group at end of initializer
    (near initialization for 'scan_init')
    excess elements in struct initializer
    (near initialization for 'scan_init')
    'nrf_ble_scan_init_t' has no member named 'connect_if_match'
    excess elements in struct initializer
    (near initialization for 'scan_init')
    'nrf_ble_scan_init_t' has no member named 'scan_evt_handler'
    excess elements in struct initializer
    (near initialization for 'scan_init')
    too few arguments to function 'nrf_ble_scan_init'
    main.c
    declared here
    redefinition of 'main'
    nrfx_timer.h
    main.c
    previous definition of 'main' was here
    implicit declaration of function 'nrf_sdh_enable_request' [-Wimplicit-function-declaration]
    'nrf_ble_scan_init_t' has no member named 'scan_param'
    extra brace group at end of initializer
    (near initialization for 'scan_init')
    excess elements in struct initializer
    (near initialization for 'scan_init')
    'nrf_ble_scan_init_t' has no member named 'connect_if_match'
    excess elements in struct initializer
    (near initialization for 'scan_init')
    'nrf_ble_scan_init_t' has no member named 'evt_handler'
    excess elements in struct initializer
    (near initialization for 'scan_init')
    too few arguments to function 'nrf_ble_scan_init'
    main.c
    declared here
    Compiling ‘SEGGER_RTT.c’
    Compiling ‘SEGGER_RTT_Syscalls_SES.c’
    Compiling ‘SEGGER_RTT_printf.c’
    Assembling ‘ses_startup_nrf52810.s’
    Assembling ‘ses_startup_nrf_common.s’
    Compiling ‘system_nrf52810.c’
    Compiling ‘auth_status_tracker.c’
    Compiling ‘ble_advdata.c’
    Compiling ‘ble_advertising.c’
    Compiling ‘ble_conn_params.c’
    Compiling ‘ble_conn_state.c’
    Compiling ‘ble_srv_common.c’
    Build failed

  • /**
     * Copyright (c) 2018 - 2021, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    
    /** @file
     *
     * @defgroup nrf_ble_scan Scanning Module
     * @{
     * @ingroup ble_sdk_lib
     * @brief Module for handling the BLE scanning.
     *
     * @details The Scanning Module handles the BLE scanning for your application.
     *          The module offers several criteria for filtering the devices available for connection,
     *          and it can also work in the simple mode without using the filtering.
     *          If an event handler is provided, your main application can react to a filter match or to the need of setting the whitelist.
     *          The module can also be configured to automatically
     *          connect after it matches a filter or a device from the whitelist.
     *
     * @note    The Scanning Module also supports applications with a multicentral link.
     */
    
    #ifndef NRF_BLE_SCAN_H__
    #define NRF_BLE_SCAN_H__
    
    #include <stdint.h>
    #include <stdbool.h>
    #include <string.h>
    #include "nrf_sdm.h"
    #include "ble.h"
    #include "ble_gap.h"
    #include "app_util.h"
    #include "sdk_errors.h"
    #include "sdk_config.h"
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    
    /**@defgroup NRF_BLE_SCAN_FILTER_MODE Filter modes
     * @{ */
    #define NRF_BLE_SCAN_NAME_FILTER       (0x01) /**< Filters the device name. */
    #define NRF_BLE_SCAN_ADDR_FILTER       (0x02) /**< Filters the device address. */
    #define NRF_BLE_SCAN_UUID_FILTER       (0x04) /**< Filters the UUID. */
    #define NRF_BLE_SCAN_APPEARANCE_FILTER (0x08) /**< Filters the appearance. */
    #define NRF_BLE_SCAN_SHORT_NAME_FILTER (0x10) /**< Filters the device short name. */
    #define NRF_BLE_SCAN_ALL_FILTER        (0x1F) /**< Uses the combination of all filters. */
    /* @} */
    
    /**@brief Macro for defining a nrf_ble_scan instance.
     *
     * @param   _name   Name of the instance.
     * @hideinitializer
     */
    #define NRF_BLE_SCAN_DEF(_name)                            \
        static nrf_ble_scan_t _name;                           \
        NRF_SDH_BLE_OBSERVER(_name ## _ble_obs,                \
                             NRF_BLE_SCAN_OBSERVER_PRIO,       \
                             nrf_ble_scan_on_ble_evt, &_name); \
    
    
    /**@brief Enumeration for scanning events.
     *
     * @details These events are propagated to the main application if a handler is provided during
     *          the initialization of the Scanning Module. @ref NRF_BLE_SCAN_EVT_WHITELIST_REQUEST cannot be
     *          ignored if whitelist is used.
     */
    typedef enum
    {
        NRF_BLE_SCAN_EVT_FILTER_MATCH,         /**< A filter is matched or all filters are matched in the multifilter mode. */
        NRF_BLE_SCAN_EVT_WHITELIST_REQUEST,    /**< Request the whitelist from the main application. For whitelist scanning to work, the whitelist must be set when this event occurs. */
        NRF_BLE_SCAN_EVT_WHITELIST_ADV_REPORT, /**< Send notification to the main application when a device from the whitelist is found. */
        NRF_BLE_SCAN_EVT_NOT_FOUND,            /**< The filter was not matched for the scan data. */
        NRF_BLE_SCAN_EVT_SCAN_TIMEOUT,         /**< Scan timeout. */
        NRF_BLE_SCAN_EVT_CONNECTING_ERROR,     /**< Error occurred when establishing the connection. In this event, an error is passed from the function call @ref sd_ble_gap_connect. */
        NRF_BLE_SCAN_EVT_CONNECTED             /**< Connected to device. */
    } nrf_ble_scan_evt_t;
    
    
    /**@brief Types of filters.
     */
    typedef enum
    {
        SCAN_NAME_FILTER,       /**< Filter for names. */
        SCAN_SHORT_NAME_FILTER, /**< Filter for short names. */
        SCAN_ADDR_FILTER,       /**< Filter for addresses. */
        SCAN_UUID_FILTER,       /**< Filter for UUIDs. */
        SCAN_APPEARANCE_FILTER, /**< Filter for appearances. */
    } nrf_ble_scan_filter_type_t;
    
    
    typedef struct
    {
        char const * p_short_name;       /**< Pointer to the short name. */
        uint8_t      short_name_min_len; /**< Minimum length of the short name. */
    } nrf_ble_scan_short_name_t;
    
    /**@brief Structure for Scanning Module initialization.
     */
     
    typedef struct
    {
        ble_gap_scan_params_t const * p_scan_param;     /**< BLE GAP scan parameters required to initialize the module. Can be initialized as NULL. If NULL, the parameters required to initialize the module are loaded from the static configuration. */
        bool                          connect_if_match; /**< If set to true, the module automatically connects after a filter match or successful identification of a device from the whitelist. */
        ble_gap_conn_params_t const * p_conn_param;     /**< Connection parameters. Can be initialized as NULL. If NULL, the default static configuration is used. */
        uint8_t                       conn_cfg_tag;     /**< Variable to keep track of what connection settings will be used if a filer match or a whitelist match results in a connection. */
    } nrf_ble_scan_init_t;
    
    
    /**@brief Structure for setting the filter status.
     *
     * @details This structure is used for sending filter status to the main application.
     */
    typedef struct
    {
        uint8_t name_filter_match       : 1; /**< Set to 1 if name filter is matched. */
        uint8_t address_filter_match    : 1; /**< Set to 1 if address filter is matched. */
        uint8_t uuid_filter_match       : 1; /**< Set to 1 if uuid filter is matched. */
        uint8_t appearance_filter_match : 1; /**< Set to 1 if appearance filter is matched. */
        uint8_t short_name_filter_match : 1; /**< Set to 1 if short name filter is matched. */
    } nrf_ble_scan_filter_match;
    
    
    /**@brief Event structure for @ref NRF_BLE_SCAN_EVT_FILTER_MATCH.
     */ 
    typedef struct
    {
        ble_gap_evt_adv_report_t const * p_adv_report; /**< Event structure for @ref BLE_GAP_EVT_ADV_REPORT. This data allows the main application to establish connection. */
        nrf_ble_scan_filter_match        filter_match; /**< Matching filters. Information about matched filters. */
    } nrf_ble_scan_evt_filter_match_t;
    
    
    /**@brief Event structure for @ref NRF_BLE_SCAN_EVT_CONNECTING_ERROR.
     */
    typedef struct
    {
        ret_code_t err_code; /**< Indicates success or failure of an API procedure. In case of failure, a comprehensive error code indicating the cause or reason for failure is provided. */
    } nrf_ble_scan_evt_connecting_err_t;
    
    
    /**@brief Event structure for @ref NRF_BLE_SCAN_EVT_CONNECTED.
     */
    typedef struct
    {
        ble_gap_evt_connected_t const * p_connected; /**< Connected event parameters. */
        uint16_t                        conn_handle; /**< Connection handle of the device on which the event occurred. */
    } nrf_ble_scan_evt_connected_t;
    
    
    /**@brief Structure for Scanning Module event data.
     *
     * @details This structure is used to send module event data to the main application when an event occurs.
     */
    typedef struct
    {
        nrf_ble_scan_evt_t scan_evt_id; /**< Type of event propagated to the main application. */
        union
        {
            nrf_ble_scan_evt_filter_match_t   filter_match;           /**< Scan filter match. */
            ble_gap_evt_timeout_t             timeout;                /**< Timeout event parameters. */
            ble_gap_evt_adv_report_t const  * p_whitelist_adv_report; /**< Advertising report event parameters for whitelist. */
            ble_gap_evt_adv_report_t const  * p_not_found;            /**< Advertising report event parameters when filter is not found. */
            nrf_ble_scan_evt_connected_t      connected;              /**< Connected event parameters. */
            nrf_ble_scan_evt_connecting_err_t connecting_err;         /**< Error event when connecting. Propagates the error code returned by the SoftDevice API @ref sd_ble_gap_scan_start. */
        } params;
        ble_gap_scan_params_t const * p_scan_params;                  /**< GAP scanning parameters. These parameters are needed to establish connection. */
    } scan_evt_t;
    
    
    /**@brief BLE scanning event handler type.
     */
    typedef void (*nrf_ble_scan_evt_handler_t)(scan_evt_t const * p_scan_evt);
    
    
    #if (NRF_BLE_SCAN_FILTER_ENABLE == 1)
    
    #if (NRF_BLE_SCAN_NAME_CNT > 0)
    typedef struct
    {
        char    target_name[NRF_BLE_SCAN_NAME_CNT][NRF_BLE_SCAN_NAME_MAX_LEN]; /**< Names that the main application will scan for, and that will be advertised by the peripherals. */
        uint8_t name_cnt;                                                      /**< Name filter counter. */
        bool    name_filter_enabled;                                           /**< Flag to inform about enabling or disabling this filter. */
    } nrf_ble_scan_name_filter_t;
    #endif
    
    #if (NRF_BLE_SCAN_SHORT_NAME_CNT > 0)
    typedef struct
    {
        struct
        {
            char    short_target_name[NRF_BLE_SCAN_SHORT_NAME_MAX_LEN]; /**< Short names that the main application will scan for, and that will be advertised by the peripherals. */
            uint8_t short_name_min_len;                                 /**< Minimum length of the short name. */
        } short_name[NRF_BLE_SCAN_SHORT_NAME_CNT];
        uint8_t name_cnt;                                               /**< Short name filter counter. */
        bool    short_name_filter_enabled;                              /**< Flag to inform about enabling or disabling this filter. */
    } nrf_ble_scan_short_name_filter_t;
    #endif
    
    #if (NRF_BLE_SCAN_ADDRESS_CNT > 0)
    typedef struct
    {
        ble_gap_addr_t target_addr[NRF_BLE_SCAN_ADDRESS_CNT]; /**< Addresses in the same format as the format used by the SoftDevice that the main application will scan for, and that will be advertised by the peripherals. */
        uint8_t        addr_cnt;                              /**< Address filter counter. */
        bool           addr_filter_enabled;                   /**< Flag to inform about enabling or disabling this filter. */
    } nrf_ble_scan_addr_filter_t;
    #endif
    
    #if (NRF_BLE_SCAN_UUID_CNT > 0)
    typedef struct
    {
        ble_uuid_t uuid[NRF_BLE_SCAN_UUID_CNT]; /**< UUIDs that the main application will scan for, and that will be advertised by the peripherals. */
        uint8_t    uuid_cnt;                    /**< UUID filter counter. */
        bool       uuid_filter_enabled;         /**< Flag to inform about enabling or disabling this filter. */
    } nrf_ble_scan_uuid_filter_t;
    #endif
    
    #if (NRF_BLE_SCAN_APPEARANCE_CNT > 0)
    typedef struct
    {
        uint16_t appearance[NRF_BLE_SCAN_APPEARANCE_CNT]; /**< Apperances that the main application will scan for, and that will be advertised by the peripherals. */
        uint8_t  appearance_cnt;                          /**< Appearance filter counter. */
        bool     appearance_filter_enabled;               /**< Flag to inform about enabling or disabling this filter. */
    } nrf_ble_scan_appearance_filter_t;
    #endif
    
    /**@brief Filters data.
     *
     * @details This structure contains all filter data and the information about enabling and disabling any type of filters.
     *          Flag all_filter_mode informs about the filter mode. If this flag is set, then all types of enabled
     *          filters must be matched for the module to send a notification to the main application. Otherwise, it is enough to match
     *          one of filters to send notification.
     */
    typedef struct
    {
    #if (NRF_BLE_SCAN_NAME_CNT > 0)
        nrf_ble_scan_name_filter_t name_filter; /**< Name filter data. */
    #endif
    #if (NRF_BLE_SCAN_SHORT_NAME_CNT > 0)
        nrf_ble_scan_short_name_filter_t short_name_filter; /**< Short name filter data. */
    #endif
    #if (NRF_BLE_SCAN_ADDRESS_CNT > 0)
        nrf_ble_scan_addr_filter_t addr_filter; /**< Address filter data. */
    #endif
    #if (NRF_BLE_SCAN_UUID_CNT > 0)
        nrf_ble_scan_uuid_filter_t uuid_filter; /**< UUID filter data. */
    #endif
    #if (NRF_BLE_SCAN_APPEARANCE_CNT > 0)
        nrf_ble_scan_appearance_filter_t appearance_filter; /**< Appearance filter data. */
    #endif
        bool all_filters_mode;                              /**< Filter mode. If true, all set filters must be matched to generate an event.*/
    } nrf_ble_scan_filters_t;
    
    #endif // NRF_BLE_SCAN_FILTER_ENABLE
    
    /**@brief Scan module instance. Options for the different scanning modes.
     *
     * @details This structure stores all module settings. It is used to enable or disable scanning modes
     *          and to configure filters.
     */
    typedef struct
    {
    #if (NRF_BLE_SCAN_FILTER_ENABLE == 1)
        nrf_ble_scan_filters_t scan_filters;                              /**< Filter data. */
    #endif
        bool                       connect_if_match;                      /**< If set to true, the module automatically connects after a filter match or successful identification of a device from the whitelist. */
        ble_gap_conn_params_t      conn_params;                           /**< Connection parameters. */
        uint8_t                    conn_cfg_tag;                          /**< Variable to keep track of what connection settings will be used if a filer match or a whitelist match results in a connection. */
        ble_gap_scan_params_t      scan_params;                           /**< GAP scanning parameters. */
        nrf_ble_scan_evt_handler_t evt_handler;                           /**< Handler for the scanning events. Can be initialized as NULL if no handling is implemented in the main application. */
        uint8_t                    scan_buffer_data[NRF_BLE_SCAN_BUFFER]; /**< Buffer where advertising reports will be stored by the SoftDevice. */
        ble_data_t                 scan_buffer;                           /**< Structure-stored pointer to the buffer where advertising reports will be stored by the SoftDevice. */
    } nrf_ble_scan_t;
    
    
    /**@brief Function for indicating that the Scanning Module is using the whitelist.
     *
     * @param[in] p_scan_ctx Pointer to the Scanning Module instance.
     *
     * @return Whether the whitelist is used.
     */
    bool is_whitelist_used(nrf_ble_scan_t const * const p_scan_ctx);
    
    
    /**@brief Function for initializing the Scanning Module.
     *
     * @param[out] p_scan_ctx   Pointer to the Scanning Module instance. This structure must be supplied by
     *                          the application. It is initialized by this function and is later used
     *                          to identify this particular module instance.
     * 
     * @param[in]  p_init       Can be initialized as NULL. If NULL, the parameters required to initialize
     *                          the module are loaded from static configuration.
     *                          If module is to establish the connection automatically, this must be initialized
     *                          with the relevant data.
     * @param[in]  evt_handler  Handler for the scanning events.
     *                          Can be initialized as NULL if no handling is implemented in the main application.
     *
     * @retval NRF_SUCCESS      If initialization was successful.
     * @retval NRF_ERROR_NULL   When the NULL pointer is passed as input.
     */
    ret_code_t nrf_ble_scan_init(nrf_ble_scan_t            * const p_scan_ctx,
                                 nrf_ble_scan_init_t const * const p_init,
                                 nrf_ble_scan_evt_handler_t        evt_handler);
    
    
    /**@brief Function for starting scanning.
     *
     * @details This function starts the scanning according to the configuration set during the initialization.
     *
     * @param[in] p_scan_ctx       Pointer to the Scanning Module instance.
     *
     * @retval    NRF_SUCCESS      If scanning started. Otherwise, an error code is returned.
     * @retval    NRF_ERROR_NULL   If NULL pointer is passed as input.
     *
     * @return                     This API propagates the error code returned by the
     *                             SoftDevice API @ref sd_ble_gap_scan_start.
     */
    ret_code_t nrf_ble_scan_start(nrf_ble_scan_t const * const p_scan_ctx);
    
    
    /**@brief Function for stopping scanning.
     */
    void nrf_ble_scan_stop(void);
    
    
    #if (NRF_BLE_SCAN_FILTER_ENABLE == 1)
    
    /**@brief Function for enabling filtering.
     *
     * @details The filters can be combined with each other. For example, you can enable one filter or several filters.
     *          For example, (NRF_BLE_SCAN_NAME_FILTER | NRF_BLE_SCAN_UUID_FILTER) enables UUID and name filters.
     *
     * @param[in] mode                  Filter mode: @ref NRF_BLE_SCAN_FILTER_MODE.
     * @param[in] match_all             If this flag is set, all types of enabled filters must be matched
     *                                  before generating @ref NRF_BLE_SCAN_EVT_FILTER_MATCH to the main application. Otherwise, it is enough to match
     *                                  one filter to trigger the filter match event.
     * @param[in] p_scan_ctx            Pointer to the Scanning Module instance.
     *
     * @retval NRF_SUCCESS              If the filters are enabled successfully.
     * @retval NRF_ERROR_INVALID_PARAM  If the filter mode is incorrect. Available filter modes: @ref NRF_BLE_SCAN_FILTER_MODE.
     * @retval NRF_ERROR_NULL           If a NULL pointer is passed as input.
     */
    ret_code_t nrf_ble_scan_filters_enable(nrf_ble_scan_t * const p_scan_ctx,
                                           uint8_t                mode,
                                           bool                   match_all);
    
    
    /**@brief Function for disabling filtering.
     *
     * @details This function disables all filters.
     *          Even if the automatic connection establishing is enabled,
     *          the connection will not be established with the first
                device found after this function is called.
     *
     * @param[in] p_scan_ctx            Pointer to the Scanning Module instance.
     *
     * @retval NRF_SUCCESS              If filters are disabled successfully.
     * @retval NRF_ERROR_NULL           If a NULL pointer is passed as input.
     */
    ret_code_t nrf_ble_scan_filters_disable(nrf_ble_scan_t * const p_scan_ctx);
    
    
    /**@brief Function for getting filter status.
     *
     * @details This function returns the filter setting and whether it is enabled or disabled.
    
     * @param[out] p_status              Filter status.
     * @param[in]  p_scan_ctx            Pointer to the Scanning Module instance.
     *
     * @retval NRF_SUCCESS               If filter status is returned.
     * @retval NRF_ERROR_NULL            If a NULL pointer is passed as input.
     */
    ret_code_t nrf_ble_scan_filter_get(nrf_ble_scan_t   * const p_scan_ctx,
                                       nrf_ble_scan_filters_t * p_status);
    
    
    /**@brief Function for adding any type of filter to the scanning.
     *
     * @details This function adds a new filter by type @ref nrf_ble_scan_filter_type_t.
     *          The filter will be added if the number of filters of a given type does not exceed @ref NRF_BLE_SCAN_UUID_CNT,
     *          @ref NRF_BLE_SCAN_NAME_CNT, @ref NRF_BLE_SCAN_ADDRESS_CNT, or @ref NRF_BLE_SCAN_APPEARANCE_CNT, depending on the filter type,
     *          and if the same filter has not already been set.
     *
     * @param[in,out] p_scan_ctx        Pointer to the Scanning Module instance.
     * @param[in]     type              Filter type.
     * @param[in]     p_data            The filter data to add.
     *
     * @retval NRF_SUCCESS                    If the filter is added successfully.
     * @retval NRF_ERROR_NULL                 If a NULL pointer is passed as input.
     * @retval NRF_ERROR_DATA_SIZE            If the name filter length is too long. Maximum name filter length corresponds to @ref NRF_BLE_SCAN_NAME_MAX_LEN.
     * @retval NRF_ERROR_NO_MEMORY            If the number of available filters is exceeded.
     * @retval NRF_ERROR_INVALID_PARAM        If the filter type is incorrect. Available filter types: @ref nrf_ble_scan_filter_type_t.
     * @retval BLE_ERROR_GAP_INVALID_BLE_ADDR If the BLE address type is invalid.
     */
    ret_code_t nrf_ble_scan_filter_set(nrf_ble_scan_t     * const p_scan_ctx,
                                       nrf_ble_scan_filter_type_t type,
                                       void const               * p_data);
    
    
    /**@brief Function for removing all set filters.
     *
     * @details The function removes all previously set filters.
     *
     * @note After using this function the filters are still enabled.
     *
     * @param[in,out] p_scan_ctx Pointer to the Scanning Module instance.
     *
     * @retval NRF_SUCCESS       If all filters are removed successfully.
     */
    ret_code_t nrf_ble_scan_all_filter_remove(nrf_ble_scan_t * const p_scan_ctx);
    
    
    #endif // NRF_BLE_SCAN_FILTER_ENABLE
    
    
    /**@brief Function for changing the scanning parameters.
     *
     **@details Use this function to change scanning parameters. During the parameter change
     *         the scan is stopped. To resume scanning, use @ref nrf_ble_scan_start.
     *         Scanning parameters can be set to NULL. If so, the default static configuration
     *         is used. For example, use this function when the @ref NRF_BLE_SCAN_EVT_WHITELIST_ADV_REPORT event is generated.
     *         The generation of this event means that there is a risk that the whitelist is empty. In such case, this function can change
     *         the scanning parameters, so that the whitelist is not used, and you avoid the error caused by scanning with the whitelist
     *         when there are no devices on the whitelist.
     *
     * @param[in,out] p_scan_ctx     Pointer to the Scanning Module instance.
     * @param[in]     p_scan_param   GAP scanning parameters. Can be initialized as NULL.
     *
     * @retval NRF_SUCCESS          If parameters are changed successfully.
     * @retval NRF_ERROR_NULL       If a NULL pointer is passed as input.
     */
    ret_code_t nrf_ble_scan_params_set(nrf_ble_scan_t        * const p_scan_ctx,
                                       ble_gap_scan_params_t const * p_scan_param);
    
    
    /**@brief Function for handling the BLE stack events of the application.
     *
     * @param[in]     p_ble_evt     Pointer to the BLE event received.
     * @param[in,out] p_scan        Pointer to the Scanning Module instance.
     */
    void nrf_ble_scan_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_scan);
    
    
    /**@brief Function for converting the raw address to the SoftDevice GAP address.
     *
     * @details This function inverts the byte order in the address. If you enter the address as it is displayed
     *          (for example, on a phone screen from left to right), you must use this function to
     *          convert the address to the SoftDevice address type.
     *
     * @note This function does not decode an address type.
     *
     * @param[out] p_gap_addr The Bluetooth Low Energy address.
     * @param[in]  addr       Address to be converted to the SoftDevice address.
     *
     * @retval NRF_ERROR_NULL                 If a NULL pointer is passed as input.
     * @retval NRF_SUCCESS                    If the address is copied and converted successfully.
     */
    ret_code_t nrf_ble_scan_copy_addr_to_sd_gap_addr(ble_gap_addr_t * p_gap_addr,
                                                     uint8_t    const addr[BLE_GAP_ADDR_LEN]);
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif // NRF_BLE_SCAN_H__
    
    /** @} */
    
             

    This is the code for nrf_ble_scan.h  

  • If you switch to S132, then you not only need to use the S132 header files, but you also need to update your project in a few more ways:

    • Remove the S112 define and define S132 instead
    • Update the application flash start address to the size of S132 (this depends on the version, so check the release notes of the version you are using)

    You may also need to do some other changes (like change the application RAM start address, but if that is needed you will get an error. Or you culd just mump it up a bit to be on the safe side (unlike the application flash start address, the RAM start address does not have to be exact, as long as it is not too low, while still leaving enough room for the application RAM requierments).

    To see an example of all this, you can take an example proejct in the SDK, and diff the project file(s) for a S112 with the project files for S132 for the same device. You will also see other unrelated changes then as typically those would also be projects fro different ICs, but you will see what I described earlier in this post.

    Regarding the build errors you get, start at the top and resolve them one by one (most likely the same root cause is responsible for many of the errors). For instance, "unknown type name 'ble_gap_scan_params_t'" means that ble_gap_scan_params_t is not defined. This is defined in ble_gap.h for the SoftDevices that support the central role, so as you get this, it indicates that you are still using the header files fro S112.

  • so as you get this, it indicates that you are still using the header files fro S112.

    Einar can you tell me , what would be the proper solution to it? like how can one add those header file present under soft device header`s folder and link them in our program? AND FOI I`m using ble_app_hrs example . removed everything and doing a fresh start .

  • You need to change the include path to point to the right SoftDevice headers. Exactly how to do this is different for each toolchain version, but all have a way to change the include path.This is a key feature for any C project so you need to learn this. If you use Segger Embedded Studio, see here:

    PS: Note that the S132 is not supported on the nRF52810 (though most will work), and you may also find yourself quickly run out of space, so if you need more features you may want to consider going for a larger device.

Reply Children
No Data
Related