Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Detect and/or decode beacon advertisements on nRF Dev board

Hello,

I am trying to find an example application that I can run on my Dev board that will allow me to detect and decode advertising beacon and send the data out of the serial/log port when the event occurs.

I am working with the nRF5 SDK 17.1.0. The dev kit is nRF52-DK.

The examples that I have seen appear to want to connect to the target which the beacon does not do.

Any suggestions?

Thanks,

Allen

  • Hello Karl,

    I rebuilt the ble_app_blinky_c using the DEBUG as described above and this was the resultant output:

    <info> app_timer: RTC: initialized.

    <error> app: ERROR 7 [NRF_ERROR_INVALID_PARAM] at C:\Allen_Data\local_projs\nRF5_SDK_17.1.0_ddde560\examples\ble_central\ble_app_blinky_c\main.c:489

    PC at: 0x0002EB7D

    <error> app: End of error report

    When I look at the line number, it has to do with the name of the device.  See the code I included in a previous reply.  The line number referenced is the same as line 14 shown above.  I am inserting an image of a screenshot from the application that shows the line number as well.

    I have tried m_target_periph_UUID as it is shown and as &m_target_periph_UUID[0].  Both give the same results.

    The definition for the m_target_periph_UUID is shown in the previous code snippet I sent earlier.

    Any ideas?

  • Hello Karl,

    Further investigation shows that the call did not expect a UUID on line 488.  I went into the config.sdk and enabled the UUID setting under scan.  Then, I redefined the variable that held the UUID array as:

    ble_uuid128_t m_target_periph_UUID; // [16] = {0x21, 0xAD, 0x05, 0x3d, 0x0d, 0x9f, 0x4b, 0x55, 0xa1, 0xd6, 0x96, 0x3f, 0x0e, 0x3d, 0xd8, 0x70};

    As a quick init, and I realize it is not good coding practice, so let's not go there, I initialized the array prior to making the call as shown below:

    // Setting filters for scanning.
    err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_UUID_FILTER, false);
    APP_ERROR_CHECK(err_code);

    m_target_periph_UUID.uuid128[0] = 0x21;
    m_target_periph_UUID.uuid128[1] = 0xAD;
    m_target_periph_UUID.uuid128[2] = 0x05;
    m_target_periph_UUID.uuid128[3] = 0x3d;
    m_target_periph_UUID.uuid128[4] = 0x0d;
    m_target_periph_UUID.uuid128[5] = 0x9f;
    m_target_periph_UUID.uuid128[6] = 0x4b;
    m_target_periph_UUID.uuid128[7] = 0x55;
    m_target_periph_UUID.uuid128[8] = 0xa1;
    m_target_periph_UUID.uuid128[9] = 0xd6;
    m_target_periph_UUID.uuid128[10] = 0x96;
    m_target_periph_UUID.uuid128[11] = 0x3f;
    m_target_periph_UUID.uuid128[12] = 0x0e;
    m_target_periph_UUID.uuid128[13] = 0x3d;
    m_target_periph_UUID.uuid128[14] = 0xd8;
    m_target_periph_UUID.uuid128[15] = 0x70;

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

    When I recompile and check the terminal output window, I get:

    <info> app_timer: RTC: initialized.

    <info> app: Blinky CENTRAL example started.

    So, I am not crashing anymore.  However, on nRF Connect app on my Android phone, I can see the beacon with the right UUID as shown above.

    Any suggestions?

    Thanks,

    Allen Shea

  • Hello Allen Shea,

    Thank you for your update - it is great to see all the steps you have taken to debug this, and you are definitively on the right path here already.

    AllenS said:
    As a quick init, and I realize it is not good coding practice, so let's not go there, I initialized the array prior to making the call as shown below:

    No worries - you can also see how the UUID for the filter is specified in the ble_app_uart_c example, since it by default scans for the custom NUS UUID.

    AllenS said:

    So, I am not crashing anymore.  However, on nRF Connect app on my Android phone, I can see the beacon with the right UUID as shown above.

    Any suggestions?

    It looks to me like you have gotten everything up and running as it should, but that the UUID you have specified does not match the UUID that your device is advertising. Could you show me the entire scan_init function you have now, along with how you have verified the UUID that the device is advertising? You might also have to reverse the byte ordering, since UUIDs are read with big endien.

    You can verify the advertised UUID either through your phone app, or through using the nRF Sniffer tool - but the former is probably the easiest, since that does not involve familiarizing with the sniffer tool first.

    Best regards,
    Karl

  • Here is the entire scan_init function:

    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 = true;
        init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;
    
        err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
        APP_ERROR_CHECK(err_code);
    
    /*
        // Setting filters for scanning.
        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_NAME_FILTER, false);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name);
        APP_ERROR_CHECK(err_code);
    */
    
        // Setting filters for scanning.
        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_UUID_FILTER, false);
        APP_ERROR_CHECK(err_code);
    
        m_target_periph_UUID.uuid128[0] = 0x21;
        m_target_periph_UUID.uuid128[1] = 0xAD;
        m_target_periph_UUID.uuid128[2] = 0x05;
        m_target_periph_UUID.uuid128[3] = 0x3d;
        m_target_periph_UUID.uuid128[4] = 0x0d;
        m_target_periph_UUID.uuid128[5] = 0x9f;
        m_target_periph_UUID.uuid128[6] = 0x4b;
        m_target_periph_UUID.uuid128[7] = 0x55;
        m_target_periph_UUID.uuid128[8] = 0xa1;
        m_target_periph_UUID.uuid128[9] = 0xd6;
        m_target_periph_UUID.uuid128[10] = 0x96;
        m_target_periph_UUID.uuid128[11] = 0x3f;
        m_target_periph_UUID.uuid128[12] = 0x0e;
        m_target_periph_UUID.uuid128[13] = 0x3d;
        m_target_periph_UUID.uuid128[14] = 0xd8;
        m_target_periph_UUID.uuid128[15] = 0x70;
    
        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &m_target_periph_UUID);
        APP_ERROR_CHECK(err_code);
    }
    

    I will look at the UUID stuff you are suggesting soon.

  • Hello Karl,

    Using nRF_Connect, I captured this raw data from the beacon advertisement:

    // Raw data captured from the beacon using nRF_Connect
    // 0x0201041AFF4C000215 21 AD 05 3D 0D 9F 4B 55 A1 D6 96 3F 0E 3D D8 70 00640000C3

    I separated the UUID from the stream so it would be easier to see.

    When you say reverse the byte order, do you mean something like initializing as shown below:

    m_target_periph_UUID.uuid128[15] = 0x21;
    m_target_periph_UUID.uuid128[14] = 0xAD;
    m_target_periph_UUID.uuid128[13] = 0x05;
    m_target_periph_UUID.uuid128[12] = 0x3d;
    m_target_periph_UUID.uuid128[11] = 0x0d;
    m_target_periph_UUID.uuid128[10] = 0x9f;
    m_target_periph_UUID.uuid128[9] = 0x4b;
    m_target_periph_UUID.uuid128[8] = 0x55;
    m_target_periph_UUID.uuid128[7] = 0xa1;
    m_target_periph_UUID.uuid128[6] = 0xd6;
    m_target_periph_UUID.uuid128[5] = 0x96;
    m_target_periph_UUID.uuid128[4] = 0x3f;
    m_target_periph_UUID.uuid128[3] = 0x0e;
    m_target_periph_UUID.uuid128[2] = 0x3d;
    m_target_periph_UUID.uuid128[1] = 0xd8;
    m_target_periph_UUID.uuid128[0] = 0x70;

    Thanks,

    Allen

Related