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,

    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.

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

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

  • On a side note, I recompiled the app with the reversed UUID as shown above and got the same results of no Beacon detection or decode with the filter.

    Going back to the RF Sniffer, how would I specify in the python example the UUID or even the MAC address as the filter.  Below is the snippet of code from the example.py file:

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

  • Hi,

    Karl is OoO so I am stepping in.

    Regarding the nRF Sniffer, that is intended to be used with Wireshark as a protocol analyzer, and the sniffer itself does not have any support for filtering on UUID or similar. So if you would want to do that you would have to implement it yourself.

    Regardign filtering UUID with the scan module in the nF5 SDK, note that the way UUIDs are handled in the SDK, you need to set the base UUID (when you get returned a UUID "type"), and later when you want to perfer to that UUID in the case of a 128 bit UUID you provide byte 12-13, and the type (see ble_uuid_t). You can see an example of this in examples/ble_central/ble_app_uart_c/main.c. If you use that as an example you also need to refer to components/ble/ble_services/ble_nus_c/ble_nus_c.c, where you can see that the base UUID is set with a call to sd_ble_uuid_vs_add(), and the type is the third parameter, which is an output from this function. (The base UUID is the full UUID, but with octet 12-13 set to 0x00).

  • Hello Einar,

    Maybe I am approaching this the wrong way.  Maybe I should look at using the Uart_c example rather than Blinky_c.  I just need a simple way to detect/decode a beacon module that does not send a name but rather sends out the MAC address and a specific fixed UUID as part of the beacon packet.  When that is detected/decoded, I would want to send it out the serial port as part of the debug log so I can capture it on the computer.  Would it be easier to move over to the Uart_c project and accomplish this or should I stay with Blinky_c?

  • I think the BLE blinky central is good as it is a simple sample. You just want to keep BLE scanning and logging, and remove the rest, so better to start off with a simpler sample with less to remove.

Related