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

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

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

Children
Related