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

Developing Beacon and Scanner using nrf52 dongle & nrf52840 DK respectively

HI as i am new to nrf nordic semiconductor development i have some quetsions regarding application im developing

I am trying to develop Ble application where nRF 52 will be the beacon and nRF 52840 DK will be the scanner module.

1.I have used nRF_SDK_15.3.0_59ac345/examples/ble_pheripheral/ble_app_beacon/pca10056/s140 program form nRF 52 dongle to operate it as a beacon when code is uploaded device gets detected on mobile nrf beacon app..and also by using printf i can varify the data which is being transmitted by beacon..

2.Second thing is i have nRF 52840 DK which i want to use it as a scanner for beacons (nRF52 dongles) .when beacons come in range of scanner it should detect the beacons and advertise      the report accordinly in debug terminal.

   For scanner application i have tried using 3 codes

1.ble_app_multipheripheral_pca10056

2.ble_app_multilinkclient_pca10056

3.ble_app_uart_c_pca10056

I am not sure about which one will work properly.as far as i tried and tested multipheripheral worked ok with nrf blinky clients.

so i want help from your side in making nRf52840 as scanner using some modifications in this codes..and so that it can scan any no of beacons of nRF52 dongles. 

Parents
  • when beacons come in range of scanner it should detect the beacons and advertise

    A beacon cannot tell when it is in range of a scanner!

    The name comes from the normal English word "beacon";  it is some thing which just shines - like a lighthouse.

  • Yea ur correct when beacon comes in range of scanner it should get detected .thats why i want to make the scanner using above code to detect those beacons .

    we dont want beacons to tell when it is in range of scanner ..

    as beacon gets connected to scanner ,scanner should either advertise the data receveid from beacon that is rssi value and UUID.and make the on mode LEDs active whan beacon is in range ..thats it..

  • /***************************************************************************************/
    /*
     * beacon_scanner
     * Created by Manuel Montenegro, Sep 7, 2018.
     *
     *  This is a Bluetooth 5 scanner. This code reads every advertisement from beacons
     *  and sends its data through serial port.
     *
     *  This code has been developed for Nordic Semiconductor nRF52840 PDK.
    */
    /***************************************************************************************/
    
    #include <stdint.h>
    #include <stdio.h>
    #include <string.h>
    #include "nordic_common.h"
    #include "nrf_sdm.h"
    #include "ble.h"
    #include "ble_hci.h"
    #include "ble_db_discovery.h"
    #include "ble_srv_common.h"
    #include "nrf_sdh.h"
    #include "nrf_sdh_ble.h"
    #include "nrf_sdh_soc.h"
    #include "nrf_pwr_mgmt.h"
    #include "app_util.h"
    #include "app_error.h"
    #include "ble_dis_c.h"
    #include "ble_rscs_c.h"
    #include "app_util.h"
    #include "app_timer.h"
    #include "bsp_btn_ble.h"
    #include "peer_manager.h"
    #include "peer_manager_handler.h"
    #include "fds.h"
    #include "nrf_fstorage.h"
    #include "ble_conn_state.h"
    #include "nrf_ble_gatt.h"
    #include "nrf_pwr_mgmt.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 identifies the BLE configuration of the SoftDevice. */
    #define APP_BLE_OBSERVER_PRIO       3                                   /**< BLE observer priority of the application. There is no need to modify this value. */
    #define APP_SOC_OBSERVER_PRIO       1                                   /**< SoC observer priority of the application. There is no need to modify this value. */
    
    #define SCAN_INTERVAL               0x0320                              /**< Determines scan interval in units of 0.625 millisecond. */
    #define SCAN_WINDOW                 0x0320                              /**< 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 continues until it is explicitly disabled. */
    
    NRF_BLE_SCAN_DEF(m_scan);                                   /**< Scanning Module instance. */
    
    static bool                  m_memory_access_in_progress;   /**< Flag to keep track of ongoing operations on persistent memory. */
    
    static ble_gap_scan_params_t m_scan_param =                 /**< Scan parameters requested for scanning and connection. */
    {
        .active        = 0x00,
        .interval      = SCAN_INTERVAL,
        .window        = SCAN_WINDOW,
        .filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
        .timeout       = SCAN_DURATION,
    //    .scan_phys     = BLE_GAP_PHY_CODED,                                 // Choose only one of the following scan_phys
        .scan_phys     = BLE_GAP_PHY_1MBPS,
    //    .scan_phys     = BLE_GAP_PHY_2MBPS,
        .extended      = 1,
    };
    
    static void scan_start(void);
    
    
    /**@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)
    {
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_ADV_REPORT:
            {
                NRF_LOG_RAW_HEXDUMP_INFO (m_scan.scan_buffer.p_data, m_scan.scan_buffer.len);
                NRF_LOG_RAW_INFO ("----------------------------------\r\n");
            }
    
            default:
                break;
        }
    }
    
    
    /**
     * @brief SoftDevice SoC event handler.
     *
     * @param[in] evt_id    SoC event.
     * @param[in] p_context Context.
     */
    static void soc_evt_handler(uint32_t evt_id, void * p_context)
    {
        switch (evt_id)
        {
            case NRF_EVT_FLASH_OPERATION_SUCCESS:
            /* fall through */
            case NRF_EVT_FLASH_OPERATION_ERROR:
    
                if (m_memory_access_in_progress)
                {
                    m_memory_access_in_progress = false;
                    scan_start();
                }
                break;
    
            default:
                // No implementation needed.
                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 handlers for BLE and SoC events.
        NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
        NRF_SDH_SOC_OBSERVER(m_soc_observer, APP_SOC_OBSERVER_PRIO, soc_evt_handler, NULL);
    }
    
    
    /**@brief Function for handling Scanning Module 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.");
                scan_start();
            } break;
    
            default:
              break;
        }
    }
    
    
    /**@brief Function for initializing the scanning and setting the filters.
     */
    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;
        init_scan.p_scan_param     = &m_scan_param;
    
        err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
        APP_ERROR_CHECK(err_code);
    }
    
    
    /**@brief Function for starting scanning.
     */
    static void scan_start(void)
    {
        ret_code_t err_code;
    
        // If there is any pending write to flash, defer scanning until it completes.
        if (nrf_fstorage_is_busy(NULL))
        {
            m_memory_access_in_progress = true;
            return;
        }
    
        err_code = nrf_ble_scan_start(&m_scan);
        APP_ERROR_CHECK(err_code);
    }
    
    
    /**@brief Function for initializing logging. */
    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 for initializing the timer. */
    static void timer_init(void)
    {
        ret_code_t err_code = app_timer_init();
        APP_ERROR_CHECK(err_code);
    }
    
    
    /**@brief Function for initializing power management.
     */
    static void power_management_init(void)
    {
        ret_code_t err_code;
        err_code = nrf_pwr_mgmt_init();
        APP_ERROR_CHECK(err_code);
    }
    
    
    /**@brief Function for handling the idle state (main loop).
     *
     * @details Handles any pending log operations, then sleeps until the next event occurs.
     */
    static void idle_state_handle(void)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            nrf_pwr_mgmt_run();
        }
    }
    
    
    
    int main(void)
    {
    
        // Initialize.
        log_init();
        timer_init();
        power_management_init();
        ble_stack_init();
        scan_init();
    
        // Start execution.
        NRF_LOG_RAW_INFO(    " ----------------\r\n");
        NRF_LOG_RAW_INFO(	 "| Beacon scanner |");
        NRF_LOG_RAW_INFO("\r\n ----------------\r\n");
        
        scan_start();
    
    
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
        }
    }
    

  • jst go through above code and let me know if any changes required ..i dose not build because of nrf_clock.c problem.which you had highlighted above in your thread

  • jst go through above code

    Have you been through it?

    dose not build because of nrf_clock.c problem

    What problem, exactly?

    What have you done to resolve that problem?

  • To resolve this problem I have downloaded nrf_clock.c form Github and paste into the modules/ nrfx/drivers/src... and tried to build the code it gives error

    as mentioned in abovethread it seems this nrf_clock.c cannot be used in nRF 15.3 SDk as it is split in this sdks

Reply Children
Related