How to pair/connect with a MAC address

I need to connect to other units according to their MAC address. I'm assuming that this:

BT_SCAN_FILTER_TYPE_ADDR
Is the thing to use in this:
bt_scan_filter_add
So instead of this:
err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_UUID, BT_UUID_XLRT_SERVICE);
You'd have this:
err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_ADDR, BT_MAC_ADDRESS);
I can see that you do this:

#define BT_UUID_XLRT_SERVICE BT_UUID_DECLARE_128(XLRT_SERVICE_UUID_VAL)

Where this:

#define XLRT_SERVICE_UUID_VAL \
BT_UUID_128_ENCODE(0x2a1f963c, 0x143a, 0x4f7d, 0x9107, 0x6315196a02a6)
Has been previously defined, but what's the syntax for defining something like BT_MAC_ADDRESS
please? Would be so helpful if you had little code snippets of how to do stuff like this.
Thanks
Parents
  • Hi

    Try something like this (assuming there are no conflicting filters already set in your project:

    1. Set up a filter for the MAC address you're interested in connecting to:
      err_code = nrf_ble_scan_copy_addr_to_sd_gap_addr(&m_mac_filter, target_mac_addr);
      err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_ADDR_FILTER, &m_mac_filter);
      m_mac_filter.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
    2. Enable the address filter:
      err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_ADDR_FILTER, false);
      APP_ERROR_CHECK(err_code);

    Setting up and enabling a filter should be done before you start scanning.

    Best regards,

    Simon

  • Hi,

    Thanks for that, but it's not answering my question in terms of the syntax for the mac address.  I guess this:

    target_mac_addr

    is where the mac address itself is stored, but what type of variable is this?

    So , for example is it a string of hie kind of format:

    45:67:A5:76:AA:FF

    Or just a hex number such as

    4567A576AAFF

    Or...?

    Thanks!

Reply Children
Related