How to scan multiple peripheral devices and get connected to one.

Hi,

I'm using nRF5340 DK, one board is programmed as central and 2 boards are programmed as peripherals. When I flash the central program it is selecting a random board and getting connected to it. All I wanted to do is after scanning the central should display all the peripherals it has scanned, later it should ask the user to input the peripheral address of choice and once user inputs the data, needs to get connected to that particular board. I'm stuck with this. Can you please help me?

Regards

Karthik Kumar

Parents
  • Hello Karthik,

    From your application you can choose whether or not to connect to the devices that you are receiving advertisements from. 

    If you study the sample found in NCS\nrf\samples\bluetooth\central_hr_coded, you can see a device that is scanning. As you can see in scan_init(), it sets .connect_if_match = 0, which makes it receive the callback scan_filter_match(), from which it tries to connect to the device that matched the filters using bt_conn_le_create(). All the functions that I mentioned are in the main.c file of this sample.

    So then it is up to you how you want to communicate with the application. How does it show you the filter matches, and how do you select which one to connect to. You mentioned buttons, so you would need a button handler (look at how the NCS\nrf\samples\bluetooth\peripheral_uart sets up and uses the button_changed() callback). 

    Best regards,

    Edvin

  • Hi Edvin,

    After the flash, I'm getting the below statements on the terminal window.

    *** Booting Zephyr OS build v2.7.0-ncs1 ***

    Bluetooth initialized Test

    Scanning successfully started

    Filters matched

    Address: C8:57:53:55:1B:50 (random) connectable: yes

    Here only one of the board is been chosen and printed randomly on the terminal, but I wanted it to print all the devices it has scanned.

    Enter the device Address:

    At this point i wanted to pass the address of the board that i wanted to connect amongst the  2 boards.

    Connection pending

    Connected: C8:57:53:55:1B:50 (random), tx_phy 4, rx_phy 4

    post which the connection should happen with the selected board. How can I do this?

    Regards

    Karthik Kumar

  • That is not entirely correct. PHY is not a special bluetooth connection feature. PHY just indicates what radio baudrate that is being used. 

    I don't know what you believe PHY is, but what does it print when you add this line to the peripheral/central uart samples? Why "is it not fruitful"?

  • Yeah sorry was confused. It is the baud rate.

    Upon including the above code there is no change with the code output it still remains the same, that is the tx_phy and rx_phy are not been printed on the terminal.

    I want to make connection via PHY, so how can I modify the code, both in central and peripheral uart.

  • Are you able to connect the central and the peripheral?

    "I want to make connection via PHY" doesn't really make any sense. If you are connected, you are certainly using a PHY. There is no way to connect without. 

    Does the log from your application indicate that the central and peripheral are connected? Or are you able to send UART data from one device to the other?

  • Yes the central and peripheral are connected. But not sure weather its using PHY. How can i confirm this

Reply Children
No Data
Related