This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to change from BLE central to peripheral mode by buttons

Hi, I was wondering how to change from central mode of the NRF52 board to peripheral mode and from peripheral mode to central mode by pressing the input buttons on the board. For example, button 1 would enable the central mode which is when the NRF52 board is acting as the client and wants to send data and then button 2 would enable the peripheral mode when the NRF52 board is advertising to be connected to another BLE device, but then disable the central mode which is button 1.

Are there any examples related to this? Any help would be appreciated.

Parents
  • Hi,

    The S130 (nRF51) and S132 (nRF52) softdevices are capable of running concurrently in peripheral and central mode with up to 8 individual links (up to 20 in latest S132 v4.0.0 alpha release). You are therefore not required to switch from central to peripheral mode and back, but you can of course do this if you want to. It is also possible to configure button presses to start advertising/scanning for a predefined period of time if this is what you want.

    I recommand that you take a look at the BLE Relay example and the BLE LE Secure Connections multirole example, which both use concurrent paripheral and central mode.

    Best regards,

    Jørgen

  • Basically, my application is used to connect to both central and/or peripheral devices.I am using a single central code which is the HRS example with some modifications because I thought it would be easier since it already had the central and peripheral implementation. However, for my application, there needs to be UART service implemented for which there is a central UART terminal which will send data to the peripheral UART terminal through the user application. This is why I used the UART example that was provided and was trying to combine both UART and the HRS example. Currently I do not have any heart rate devices but other devices such as GoPro that I want to connect. Is this alright to do or do we need to handle it in a different way?

    UPDATE: Also wanted to ask how I can use the uart_event_handle() in the HRS example? It contains the necessary function ble_nus_c_string_send which would allow the user to send information through UART. It is because in the UART example, it is called in the uart_init() method which cannot be used for the HRS example like you described.

Reply
  • Basically, my application is used to connect to both central and/or peripheral devices.I am using a single central code which is the HRS example with some modifications because I thought it would be easier since it already had the central and peripheral implementation. However, for my application, there needs to be UART service implemented for which there is a central UART terminal which will send data to the peripheral UART terminal through the user application. This is why I used the UART example that was provided and was trying to combine both UART and the HRS example. Currently I do not have any heart rate devices but other devices such as GoPro that I want to connect. Is this alright to do or do we need to handle it in a different way?

    UPDATE: Also wanted to ask how I can use the uart_event_handle() in the HRS example? It contains the necessary function ble_nus_c_string_send which would allow the user to send information through UART. It is because in the UART example, it is called in the uart_init() method which cannot be used for the HRS example like you described.

Children
No Data
Related