scan with UUID filter

My project is developed on nRF52840, it needs to communication with a mobile device through BLE,  nRF52840 is as central. The mobile device starts BLE advertising, then, nRF52840 starts scanning, I only want to connect with that mobile device, I added UUID filter, but it did not work. I have two questions,

1. may I extract UUID from advertising data: ad.?

static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
             struct net_buf_simple *ad)
2. how to add an uuid filter for BLE scanning.? I used below code, it did not work.
static int scan_init(void)
{
    int err;
    struct bt_scan_init_param scan_init = {
        .connect_if_match = 1,
    };

    bt_scan_init(&scan_init);
    bt_scan_cb_register(&scan_cb);

    err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_UUID, BT_UUID_DECLARE_16(0x5300));
    if (err) {
        return err;
    }

    err = bt_scan_filter_enable(BT_SCAN_UUID_FILTER, false);
    if (err) {
        return err;
    }

    return err;
}
Please help !
Mark,
Parents
  • Hi,

    I recommend that you go through the Bluetooth Low Energy Fundamentals course at our academy pages to learn more about the scanning procedure as well as general BLE theory and development: https://academy.nordicsemi.com/courses/bluetooth-low-energy-fundamentals/. This course should show you how to scan with UUID filter.

    Kind regards,
    Andreas

  • All samples in that course only implement BLE peripheral on Nordic board, but, I need to use the Nordic board as BLE central, it scans for BLE device with UUID filter, when the mobile device with that service UUID is found, it will connect to it, then, exchange data.

    could you provide an sample to implement a BLE central on nRF52840 with Zephry.

    Thanks,

    Mark,

  • I may scan my mobile device by filter with name in initialization:

    static int scan_init(void)
    {
        int err;
        struct bt_scan_init_param scan_init = {
            .connect_if_match = 1,
        };
     

        bt_scan_init(&scan_init);
        bt_scan_cb_register(&scan_cb);

        err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME,"MobileID");
        if (err) {
            return err;
        }

        err = bt_scan_filter_enable(BT_SCAN_NAME_FILTER, false);
        if (err) {
            return err;
        }

        return err;
    }
    But, if I change the filter to UUID, no match was found.
    I could scan the mobile device with nRF Connect App, the UUID is shown:
    00005300-5a07-4768-b762-7394cc35863a.
    I used UUID generated as:
    #define MOBILEID_SERVICE_UUID   BT_UUID_DECLARE_128(0x00, 0x00, 0x53, 0x00, \
                                                            0x5a, 0x07, 0x47, 0x68, 0xb7, 0x62, \
                                                            0x73, 0x94, 0xcc, 0x35, 0x86, 0x3a)
    err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_UUID, MOBILEID_SERVICE_UUID);
    please help.
    mark,
  • The issue was solved, the UUID data order should be reversed.

Reply Children
  • Hi Mark,

    Apologies for the long response time. There has been 5 days of holidays/weekend here in Norway since my last reply.

    mark.zhang said:

    All samples in that course only implement BLE peripheral on Nordic board, but, I need to use the Nordic board as BLE central, it scans for BLE device with UUID filter, when the mobile device with that service UUID is found, it will connect to it, then, exchange data.

    could you provide an sample to implement a BLE central on nRF52840 with Zephry.

    As for samples that showcases how to scan for a certain UUID from a centrals perspective, you can have a look at the Central_UART sample where it starts to scan for the UUID of the Nordic UART Service: https://github.com/nrfconnect/sdk-nrf/blob/831e3627aa67890791794ef82588a2d68ce17c0b/samples/bluetooth/central_uart/src/main.c#L488 

    mark.zhang said:
    The issue was solved, the UUID data order should be reversed.

    Noted, could you also clarify if this means that your entire inquery has been resolved? If not please let me know if you have any remaining questions not answered!

    Kind regards,
    Andreas

Related