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

Beacon Scanner Problem

Hello,

I have beacon advertiser and scanner. Scanner is scanning the devices from around. But its not scanning the device that i used for advertising. On the other side, NRF Connet application able to scan my advertising device. I have attached my Scanner and Advertising beacon code. Please, can you check why i am not getting the my advertising device on scanner side. Can you guide me to add the filter so it can scan only device from NRF and NRF Beacon.

Thanks

Scanner.cpp

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_soc.h"
#include "nrf_pwr_mgmt.h"
#include "ble.h"
#include "nrf_delay.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.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_DURATION                   0x0000                              /**< Timout when scanning. 0x0000 disables timeout. */
#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. */

static ble_gap_scan_params_t const m_scan_params =
{
    .extended = 0,
    .report_incomplete_evts = 0,
    .active   = 1,
    .filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
    .scan_phys = BLE_GAP_PHY_1MBPS,
    .interval = SCAN_INTERVAL,
    .window   = SCAN_WINDOW,
    .timeout  = SCAN_DURATION
};

static uint8_t m_scan_buffer_data[BLE_GAP_SCAN_BUFFER_MIN]; /**< 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
};

static void scan_start(void)
{
    (void) sd_ble_gap_scan_stop();
    sd_ble_gap_scan_start(&m_scan_params, &m_scan_buffer);
}

uint8_t * adv_address = 0; int8_t rssi = 0; uint8_t * adv_data = 0;

static void on_adv_report(ble_gap_evt_adv_report_t const * p_adv_report)
{
    adv_address = (uint8_t *)p_adv_report->peer_addr.addr;
    rssi = (int8_t)p_adv_report->rssi;
    adv_data = (uint8_t *)p_adv_report->data.p_data;
    
    //if(adv_address[0] == 0x73 && adv_address[1] == 0xE8)
    //{
    printf("MAC ID");
    for(int i=0;i<6;i++)
    {
    printf(":%02X",adv_address[i]);
    }
    printf("\tDATA: ");
    for(int j=0;j<16;j++)
    {
    printf("%02X",adv_data[j]);
    }
    printf("\tRSSI: %d DB\n", rssi);
    nrf_delay_ms(1000);
    //}
}

static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;

    switch (p_ble_evt->header.evt_id)
    {

        case BLE_GAP_EVT_ADV_REPORT:
        {
            on_adv_report(&p_gap_evt->params.adv_report);

        } break;

        default:
          break;
    }
}

static void ble_stack_init(void)
{ 
  uint32_t ram_start = 0;
  nrf_sdh_enable_request();
  nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
  nrf_sdh_ble_enable(&ram_start);
  NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
}

int main(void)
{
    NRF_LOG_INIT(NULL);
    NRF_LOG_DEFAULT_BACKENDS_INIT();
    nrf_pwr_mgmt_init();
    ble_stack_init();
    
    while(1)
    {
      scan_start();
      NRF_LOG_FLUSH();
      nrf_pwr_mgmt_run();
    }
}
Adv_beacon.cpp

#include <stdbool.h>
#include <stdint.h>
#include "nordic_common.h"
#include "nrf_soc.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "ble_advdata.h"
#include "nrf_pwr_mgmt.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"


#define APP_BLE_CONN_CFG_TAG            1                                  /**< A tag identifying the SoftDevice BLE configuration. */
#define NON_CONNECTABLE_ADV_INTERVAL    MSEC_TO_UNITS(100, UNIT_0_625_MS)  /**< The advertising interval for non-connectable advertisement (100 ms). This value can vary between 100ms to 10.24s). */
#define APP_BEACON_INFO_LENGTH          0x17                               /**< Total length of information advertised by the Beacon. */
#define APP_ADV_DATA_LENGTH             0x15                               /**< Length of manufacturer specific data in the advertisement. */
#define APP_DEVICE_TYPE                 0x02                               /**< 0x02 refers to Beacon. */
#define APP_MEASURED_RSSI               0xC3                               /**< The Beacon's measured RSSI at 1 meter distance in dBm. */
#define APP_COMPANY_IDENTIFIER          0x0059                             /**< Company identifier for Nordic Semiconductor ASA. as per www.bluetooth.org. */
#define APP_MAJOR_VALUE                 0x01, 0x02                         /**< Major value used to identify Beacons. */
#define APP_MINOR_VALUE                 0x03, 0x04                         /**< Minor value used to identify Beacons. */
#define APP_BEACON_UUID                 0x01, 0x12, 0x23, 0x34, \
                                        0x45, 0x56, 0x67, 0x78, \
                                        0x89, 0x9a, 0xab, 0xbc, \
                                        0xcd, 0xde, 0xef, 0xf0            /**< Proprietary UUID for Beacon. */

static ble_gap_adv_params_t m_adv_params;                                  /**< Parameters to be passed to the stack when starting advertising. */
static uint8_t              m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; /**< Advertising handle used to identify an advertising set. */
static uint8_t              m_enc_advdata[BLE_GAP_ADV_SET_DATA_SIZE_MAX];  /**< Buffer for storing an encoded advertising set. */

static ble_gap_adv_data_t m_adv_data =
{
    .adv_data =
    {
        .p_data = m_enc_advdata,
        .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
    },
    .scan_rsp_data =
    {
        .p_data = NULL,
        .len    = 0

    }
};


static uint8_t m_beacon_info[APP_BEACON_INFO_LENGTH] =                    /**< Information advertised by the Beacon. */
{
    APP_DEVICE_TYPE,     // Manufacturer specific information. Specifies the device type in this
                         // implementation.
    //APP_ADV_DATA_LENGTH, // Manufacturer specific information. Specifies the length of the
                         // manufacturer specific data in this implementation.
    //APP_BEACON_UUID,     // 128 bit UUID value.
    //APP_MAJOR_VALUE,     // Major arbitrary value that can be used to distinguish between Beacons.
    //APP_MINOR_VALUE,     // Minor arbitrary value that can be used to distinguish between Beacons.
    //APP_MEASURED_RSSI    // Manufacturer specific information. The Beacon's measured TX power in
                         // this implementation.
};

static void advertising_init(void)
{
    uint32_t      err_code;
    ble_advdata_t advdata;
    uint8_t       flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
    ble_advdata_manuf_data_t manuf_specific_data;

    manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
    manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info;
    manuf_specific_data.data.size   = APP_BEACON_INFO_LENGTH;

    // Build and set advertising data.
    memset(&advdata, 0, sizeof(advdata));

    advdata.name_type             = BLE_ADVDATA_NO_NAME;
    advdata.flags                 = flags;
    advdata.p_manuf_specific_data = &manuf_specific_data;

    // Initialize advertising parameters (used when starting advertising).
    memset(&m_adv_params, 0, sizeof(m_adv_params));

    m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
    m_adv_params.p_peer_addr     = NULL;    // Undirected advertisement.
    m_adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
    m_adv_params.interval        = NON_CONNECTABLE_ADV_INTERVAL;
    m_adv_params.duration        = 0;       // Never time out.

    ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
    sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
}

static void advertising_start(void)
{
   sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
}

static void ble_stack_init(void)
{
   uint32_t ram_start = 0;
   nrf_sdh_enable_request();
   nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
   nrf_sdh_ble_enable(&ram_start);
}

static void log_init(void)
{
    NRF_LOG_INIT(NULL);
    NRF_LOG_DEFAULT_BACKENDS_INIT();
}

int main(void)
{
    log_init();
    nrf_pwr_mgmt_init();
    ble_stack_init();
    advertising_init();
    advertising_start();
    while(1)
    {
        nrf_pwr_mgmt_run();
    }
}

Parents
  • I quickly ran your code and could see that the scanner is getting the adv packets as they should.Check  the RTT log data below

    MAC ID:CD:81:5B:10:66:D9 DATA: 0201041AFF5900020000000000000000 RSSI: -23 DB
    MAC ID:06:B8:4E:BB:27:05 DATA: 1EFF060001092000C6E93350B9720A33 RSSI: -79 DB
    MAC ID:D3:6C:E0:FE:34:C4 DATA: 0201041AFF5900021501122334455667 RSSI: -79 DB
    MAC ID:C0:DE:5E:43:DB:66 DATA: 02011A0AFF4C001005031CE8AE705667 RSSI: -90 DB
    MAC ID:06:B8:4E:BB:27:05 DATA: 1EFF060001092000C6E93350B9720A33 RSSI: -80 DB
    MAC ID:DC:73:76:6D:E3:D1 DATA: 0319C103020106030312180609313233 RSSI: -84 DB
    MAC ID:EF:20:CF:E4:50:21 DATA: 1EFF06000109200072777984CDA5A26E RSSI: -69 DB
    MAC ID:E3:5B:83:A1:41:2C DATA: 0201190503BEFE26FE0DFF01095110F1 RSSI: -74 DB
    MAC ID:DC:73:76:6D:E3:D1 DATA: 0319C103020106030312180609313233 RSSI: -84 DB
    MAC ID:9A:07:A8:F4:CB:36 DATA: 1EFF06000109200032C558CB1E59B564 RSSI: -74 DB
    MAC ID:DC:73:76:6D:E3:D1 DATA: 0319C103020106030312180609313233 RSSI: -82 DB
    MAC ID:CD:81:5B:10:66:D9 DATA: 0201041AFF5900020000000000000000 RSSI: -21 DB
    MAC ID:9A:07:A8:F4:CB:36 DATA: 1EFF06000109200032C558CB1E59B564 RSSI: -78 DB
    MAC ID:CD:81:5B:10:66:D9 DATA: 0201041AFF5900020000000000000000 RSSI: -23 DB
    MAC ID:DE:84:3E:89:4E:10 DATA: 0201061107669A0C2000089A94E3117B RSSI: -88 DB

  • Sorry there, there seems to be a glitch in my thread queue as this thread seems to be unanswered for many days (not intentional). do you still have this problem?

    Most of us on holidays until New year. We will get back to you once we are back to office after 2nd January. We appreciate your patience. 

Reply Children
No Data
Related