Selective Connection To a Specific Gateway

Hello!

I am having 3 nrf5340 devices; 2 Gateways and 1 Headset. I am trying to achieve the scenario where I can allow the Headset connects to selectively one of the 2 Gateways using a button on the headset as an interface for the user, and if the user presses on the button, the connection is shifted to the other Gateway.

Based on my observation in BIS, I noticed that the connection is established using the MAC Random Address, and since the Random Address keeps changing every time, my current solution is to store the random address of the Gateway that connects first to the headset and once the user presses on the button (i.e. to change the connection to a different Gateway), the headset keeps scanning until it receives another Random address, and using the function API bt_addr_le_cmp(const bt_addr_le_t *a, const bt_addr_le_t *b), I compare the newly arrived address with Gateway address that is stored previously. If both addresses match, the headset scans again for another random address, and if the addresses are different, it indicates that a new device has been found and thus connects to the new address and also stores its address (as in Gateway1 previously) for future comparisons. That way I can assure to connect to a new Gateway every time the user presses on the button on the Headset.

However, I do not think that solution is optimized enough because sometimes the scanning keeps receiving the same random address over and over again and thus taking so much time until it randomly picks up the new address. I would like to hear from you on how I can optimize this connection process. I am still new to the Nordic nrf 5340 development, and your advice is highly appreciated!

  • Hi Edvin,

    I checked my bluetooth.h file to see the available API to use, I noticed that bt_le_whitelist_add() is available and the function bt_le_filter_accept_list_add() is not available. It seems that the software version you are referring to is newer than mine, but what wanders me is that calling all the functions related to whitelist cause a compilation error while other functions from bluetooth.h file are ok to use! 

    I referred also to your second suggested solution regarding the directed advertising. May I know the path of the main.c you are referring to in order to paste the if-else conditions within? I have found the other main.c file where the advertisement starts is being implemented, but not specifically where connect() function is defined.

    Thanks!

  • I checked NCS v1.7.1, where bt_le_whitelist_add() is not deprecated, and there you need to add CONFIG_BT_WHITELIST to your prj.conf.

    I was just looking at the uart examples. They don't use the BT_LE_ADV_CONN_DIR(_peer), but you can add it. 

    You can see where it is defined by using the right click and "go to definition" and look around for how things are implemented. If you can't do this, you should install nRF Connect for VS Code. 

Related