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

Parents
  • Hello Allen,

    You should use the Scanning Module to achieve this, and you can see an example of how this can be used in the BLE Blinky example.
    This way, you will have the advertising reports that match the filters you have added received in the scan module event handler.

    Best regards,
    Karl

  • Hello Karl,

    Thank you for pointing me in a direction to start.  Since this specific client application requires a device with the name "Nordic_Blinky", how can I go about looking for a specific UUID that would be embedded in the beacon advertising data instead?

  • Hello Karl,

    Just an update.  I made some changes to the example project ble_app_blinky_c.  Below are the changes made:

    // added to the variable section at the top of main
    
    static uint8_t const m_target_periph_UUID[16] = {0x21, 0xAD, 0x05, 0x3d, 0x0d, 0x9f, 0x4b, 0x55, 0xa1, 0xd6, 0x96, 0x3f, 0x0e, 0x3d, 0xd8, 0x70};
    
    // -----------------------------------------------------------------------------------------
    
    // added to the routine -> static void scan_init(void)
    
        // Setting filters for scanning.
        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_UUID_FILTER, false);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, m_target_periph_UUID);
        APP_ERROR_CHECK(err_code);
    
    //---------------------------------------------------------------------------------------
    
    // commented out the lines in routine -> 
    
    /*
        // 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);
    */
    
    

    Prior to making those changes, I ran the client application and saw this on the terminal window:

    <info> app_timer: RTC: initialized.

    <info> app: Blinky CENTRAL example started.

    After I made the changes for UUID detection as noted above in the code window, I see this come out on the terminal window:

    <info> app_timer: RTC: initialized.

    <error> app: Fatal error

    <warning> app: System reset

    <info> app_timer: RTC: initialized.

    <error> app: Fatal error

    <warning> app: System reset

    <info> app_timer: RTC: initialized.

    <error> app: Fatal error

    <warning> app: System reset

    Any suggestions?

    Thanks,

    Allen

  • Hello again, Allen

    AllenS said:
    Thank you for pointing me in a direction to start. 

    No problem at all, I am happy to help! :) 

    AllenS said:
    Since this specific client application requires a device with the name "Nordic_Blinky", how can I go about looking for a specific UUID that would be embedded in the beacon advertising data instead?

    Yes, you will have to modify the filter so that it matches the advertisements made by your beacon. For instance, if you beacon is advertising with a specific name you can change the Nordic_Blinky name used in the filter already, or if the Beacon advertises a specific address or appearance, you can filter on that instead.

    Do you already know the contents of the advertising of the beacon you are interested in?
    If not, then I would suggest using the nRF Sniffer tool to take a closer look at it.

    AllenS said:
    After I made the changes for UUID detection as noted above in the code window, I see this come out on the terminal window:

    Please make sure to add DEBUG to your preprocessor defines, like shown in the included image:

    This will make your logger module output a detailed error message whenever a non-NRF_SUCCESS error code is passed to an APP_ERROR_CHECK.
    Please do this, and let me know what this error message reads, and which line it is pointing to in your code.

    Best regards,
    Karl

Reply
  • Hello again, Allen

    AllenS said:
    Thank you for pointing me in a direction to start. 

    No problem at all, I am happy to help! :) 

    AllenS said:
    Since this specific client application requires a device with the name "Nordic_Blinky", how can I go about looking for a specific UUID that would be embedded in the beacon advertising data instead?

    Yes, you will have to modify the filter so that it matches the advertisements made by your beacon. For instance, if you beacon is advertising with a specific name you can change the Nordic_Blinky name used in the filter already, or if the Beacon advertises a specific address or appearance, you can filter on that instead.

    Do you already know the contents of the advertising of the beacon you are interested in?
    If not, then I would suggest using the nRF Sniffer tool to take a closer look at it.

    AllenS said:
    After I made the changes for UUID detection as noted above in the code window, I see this come out on the terminal window:

    Please make sure to add DEBUG to your preprocessor defines, like shown in the included image:

    This will make your logger module output a detailed error message whenever a non-NRF_SUCCESS error code is passed to an APP_ERROR_CHECK.
    Please do this, and let me know what this error message reads, and which line it is pointing to in your code.

    Best regards,
    Karl

Children
  • Hello Karl,

    I do know the contents of the advertising beacon and thought the RF Sniffer would be a good tool to investigate.  I got the tool to run once I had installed Python and found the example.py file to experiment with.  Within the file, I found a spot where I could identify a specific name but am unable to figure out how to specify either the UUID or the MAC address for the beacon.  Can you assist with that.  Below is the lines of code from the example.py file:

    # Find device with name "Example".
    dev = d.find('Example')

    As for the debug, I will investigate that a little further soon and see what I can determine and report back.

  • 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.

Related