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

ble_active_scanner Devzone example won't build

Hi all, I recently downloaded a custom built example project for Segger that simply scans for nearby Bluetooth devices and dumps the info to UART. However, even after putting the file into the SDK 15.2 examples section, the project fails to build as a number of the header files included simply aren't recognized. I attempted to remove and replace each of the specified files with no luck.

/**
 * Copyright (c) 2016 - 2018, 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.
 * 
 */
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "nordic_common.h"
#include "app_error.h"
#include "app_uart.h"
#include "ble_db_discovery.h"
#include "app_timer.h"
#include "app_util.h"
#include "bsp_btn_ble.h"
#include "ble.h"
#include "ble_gap.h"
#include "ble_hci.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_soc.h"
#include "ble_advdata.h"
#include "nrf_ble_scan.h"

#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

#define APP_BLE_CONN_CFG_TAG        1                                   /**< Tag that refers to the BLE stack configuration set with @ref sd_ble_cfg_set. The default tag is @ref BLE_CONN_CFG_TAG_DEFAULT. */
#define APP_BLE_OBSERVER_PRIO       3                                   /**< BLE observer priority of the application. There is no need to modify this value. */
#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_DURATION               0x0000                              /**< Duration of the scanning in units of 10 milliseconds. If set to 0x0000, scanning will continue until it is explicitly disabled. */

static ble_gap_scan_params_t m_scan_param;                                /**< Scan parameters requested for scanning and connection. */
static uint8_t               m_scan_buffer_data[BLE_GAP_SCAN_BUFFER_MIN]; /**< buffer where advertising reports will be stored by the SoftDevice. */

/**@brief Pointer to the buffer where advertising reports will be stored by the SoftDevice. */
static ble_data_t m_scan_buffer =
{
    m_scan_buffer_data,
    BLE_GAP_SCAN_BUFFER_MIN
};


/**@brief Function for handling asserts in the SoftDevice.
 *
 * @details This function is called in case of an assert in the SoftDevice.
 *
 * @warning This handler is only an example and is not meant for the final product. You need to analyze
 *          how your product is supposed to react in case of assert.
 * @warning On assert from the SoftDevice, the system can only recover on reset.
 *
 * @param[in] line_num     Line number of the failing assert call.
 * @param[in] p_file_name  File name of the failing assert call.
 */
void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name)
{
    app_error_handler(0xDEADBEEF, line_num, p_file_name);
}


/**@brief Function for handling BLE events.
 *
 * @param[in]   p_ble_evt   Bluetooth stack event.
 * @param[in]   p_context   Unused.
 */
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;
    }
}


/**@brief Function for initializing the BLE stack.
 *
 * @details Initializes the SoftDevice and the BLE event interrupt.
 */
static void ble_stack_init(void)
{
    ret_code_t err_code;

    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);

    // Register a handler for BLE events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
}


/**@brief Function for initializing the nrf log module. */
static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}


/**@brief Function to start scanning. */
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);
}


int main(void)
{
    ret_code_t ret;

    // Initialize.
    log_init();
    ble_stack_init();

    // Start scanning.
    NRF_LOG_INFO("BLE active scanner started.");
    scan_start();

    // Enter main loop.
    for (;;)
    {
        NRF_LOG_PROCESS();
    }
}
sdk_config.h

The main problem appears to be that the project is looking for a folder that doesn't exist : libraries\experimental_log\src. I tried creating that folder and copying all of the necessary files into it but Segger still won't recognize them. Any ideas?

Parents
  • Hi.

    Where did you download this project?

    The main problem appears to be that the project is looking for a folder that doesn't exist : libraries\experimental_log\src. I tried creating that folder and copying all of the necessary files into it but Segger still won't recognize them. Any ideas?

     The experimental_log library is not found in SDK 15.2, you can find it in SDK versions before 15.2, for example SDK 15.0.

    Best regards,

    Andreas

  • Thanks, Andreas. I actually downloaded it off of the Devzone here. It was an older post but the Dev made two versions, and the second was for 15.2. However, I managed to get around that error by including the proper paths to the files. It's the second error that really has me confused.

Reply Children
  • Hi.

    I've looked at your sdk_config.h file, and the reason you get the error "NRF_BLE_SCAN_BUFFER undeclared here", is because it is not defined in your sdk_config.h file.

    If you take a look at for example the examples\ble_central\ble_app_blinky_c folder, and its sdk_config.h file:

    // <e> NRF_BLE_SCAN_ENABLED - nrf_ble_scan - Scanning Module
    //==========================================================
    #ifndef NRF_BLE_SCAN_ENABLED
    #define NRF_BLE_SCAN_ENABLED 1
    #endif
    // <o> NRF_BLE_SCAN_BUFFER - Data length for an advertising set. 
    #ifndef NRF_BLE_SCAN_BUFFER
    #define NRF_BLE_SCAN_BUFFER 31
    #endif
    
    // <o> NRF_BLE_SCAN_NAME_MAX_LEN - Maximum size for the name to search in the advertisement report. 
    #ifndef NRF_BLE_SCAN_NAME_MAX_LEN
    #define NRF_BLE_SCAN_NAME_MAX_LEN 32
    #endif
    
    // <o> NRF_BLE_SCAN_SHORT_NAME_MAX_LEN - Maximum size of the short name to search for in the advertisement report. 
    #ifndef NRF_BLE_SCAN_SHORT_NAME_MAX_LEN
    #define NRF_BLE_SCAN_SHORT_NAME_MAX_LEN 32
    #endif
    
    // <o> NRF_BLE_SCAN_SCAN_INTERVAL - Scanning interval. Determines the scan interval in units of 0.625 millisecond. 
    #ifndef NRF_BLE_SCAN_SCAN_INTERVAL
    #define NRF_BLE_SCAN_SCAN_INTERVAL 160
    #endif
    
    // <o> NRF_BLE_SCAN_SCAN_DURATION - Duration of a scanning session in units of 10 ms. Range: 0x0001 - 0xFFFF (10 ms to 10.9225 ms). If set to 0x0000, the scanning continues until it is explicitly disabled. 
    #ifndef NRF_BLE_SCAN_SCAN_DURATION
    #define NRF_BLE_SCAN_SCAN_DURATION 0
    #endif
    
    // <o> NRF_BLE_SCAN_SCAN_WINDOW - Scanning window. Determines the scanning window in units of 0.625 millisecond. 
    #ifndef NRF_BLE_SCAN_SCAN_WINDOW
    #define NRF_BLE_SCAN_SCAN_WINDOW 80
    #endif
    
    // <o> NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL - Determines minimum connection interval in milliseconds. 
    #ifndef NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL
    #define NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL 7.5
    #endif
    
    // <o> NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL - Determines maximum connection interval in milliseconds. 
    #ifndef NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL
    #define NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL 30
    #endif
    
    // <o> NRF_BLE_SCAN_SLAVE_LATENCY - Determines the slave latency in counts of connection events. 
    #ifndef NRF_BLE_SCAN_SLAVE_LATENCY
    #define NRF_BLE_SCAN_SLAVE_LATENCY 0
    #endif
    
    // <o> NRF_BLE_SCAN_SUPERVISION_TIMEOUT - Determines the supervision time-out in units of 10 millisecond. 
    #ifndef NRF_BLE_SCAN_SUPERVISION_TIMEOUT
    #define NRF_BLE_SCAN_SUPERVISION_TIMEOUT 4000
    #endif
    
    // <o> NRF_BLE_SCAN_SCAN_PHY  - PHY to scan on.
     
    // <0=> BLE_GAP_PHY_AUTO 
    // <1=> BLE_GAP_PHY_1MBPS 
    // <2=> BLE_GAP_PHY_2MBPS 
    // <4=> BLE_GAP_PHY_CODED 
    // <255=> BLE_GAP_PHY_NOT_SET 
    
    #ifndef NRF_BLE_SCAN_SCAN_PHY
    #define NRF_BLE_SCAN_SCAN_PHY 1
    #endif
    
    // <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
    #endif
    
    // <o> NRF_BLE_SCAN_NAME_CNT - Number of name filters. 
    #ifndef NRF_BLE_SCAN_NAME_CNT
    #define NRF_BLE_SCAN_NAME_CNT 1
    #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 0
    #endif
    
    // <o> NRF_BLE_SCAN_ADDRESS_CNT - Number of address filters. 
    #ifndef NRF_BLE_SCAN_ADDRESS_CNT
    #define NRF_BLE_SCAN_ADDRESS_CNT 0
    #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
    
    // </e>
    
    // </e>

    There are several defines needed for a central.

    Best regards,

    Andreas

  • Thanks, Andreas. I went ahead and moved that section of code into my sdk_config.h. However, I now get an even more confusing error.

    I'm not familiar with object files all that much unfortunately.

  • Hi.

    I think you got this error because you have added the files nrf_ble_scan.c and nrf_ble_scan.h to your project twice, could you remove these two in the Application folder?

    Best regards,

    Andreas

  • That did it! Thanks for all your help. Also, I was wondering...is there any place that lists what header files go with certain macros? I sometimes find it tricky to locate .h stuff for a function without a reference.

  • Hi.

    We don't have a list for this unfortunately.

    Best regards,

    Andreas

Related