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

  • Ok, in that case, you have to disable the UART logging (you can change it to RTT logging) so that you free up the UART. Then you need to print the scanned adresses over UART when you scan them, and then you need to interpret the incoming UART data. You can look at the NCS\nrf\samples\bluetooth\peripheral_uart sample to see how to send and receive data through the UART.

    Best regards,

    Edvin

  • Hi Edvin,

    Thank you for the suggestion.

    In this case how can I send a particular set of data from peripheral to central via Bluetooth. That is which part of peripheral program is actually sending the packets to central.

    Regards

    Karthik Kumar

  • Look at how the peripheral_uart sample handles the incoming uart data and transmits it to the central using bt_nus_send() (look at the implementation of bt_nus_send()).

    In case you are stuck, I wrote a guide about a month ago. It also has some explanation around what functions that are used:

    https://github.com/edvinand/custom_ncs_ble_service_sample

    Best regards,

    Edvin

  • Hi Edvin,

    "Ok, in that case, you have to disable the UART logging (you can change it to RTT logging) so that you free up the UART. Then you need to print the scanned adresses over UART when you scan them, and then you need to interpret the incoming UART data. You can look at the NCS\nrf\samples\bluetooth\peripheral_uart sample to see how to send and receive data through the UART."

    Previously you had suggested me the above example and yes it is working for me. Now how can I get connected via PHY for the same peripheral UART example. I tried incorporating the below show piece of code but its not fruitful.

    err = bt_conn_get_info(conn, &info);
    if (err) {
    printk("Failed to get connection info\n");
    } else {
    const struct bt_conn_le_phy_info *phy_info;
    phy_info = info.le.phy;
    printk("Connected: %s, tx_phy %u, rx_phy %u\n",
    addr, phy_info->tx_phy, phy_info->rx_phy);
    }

    Can you please suggest me the changes that has to be made for PHY connection both on peripheral UART and central UART.

    Regards

    Karthik Kumar

  • Hello Karthik, 

    What do you mean by "connected via PHY"? And what are you trying to do with the piece of code that you pasted here? How does it behave, and what do you expect it to behave like?

    Best regards,

    Edvin

Related