Transfer exisiting application nrf52840 SD 6.1.1 from Peripheral to Central and Peripheral Mode.

We do have standalone applications developed in nrf52840, SD 6.1.1 Peripheral and Central individually, and working perfect.  

Now we want to merge both applications based on our requirements. Let say based on one event My primary peripheral application should work as central and peripheral mode both simultaneously.

Background of both applications

  • Peripheral : --- This application is collecting data from on board sensor periodically and saving it to the memory, and sending those data chunks whenever central (let say Mobile app and other central device) is requesting.
  • Central :--- which scans nearby peripheral device and connects based on filters and connects to more than one peripheral sensor through BLE. After connecting it reading data from more than one peripheral. periodically.

Question I have is,

  • I want to switch the role between peripheral to central based on event frequently, how can I do that?
  • Which examples from SDK 15.3.0_59ac345 is more relevant to my application “ multirole_lesc” or “hrs_rscs_relay” from ble_central_and_peripheralàexperimental ?
  • How ble_conn_state_role(conn_handle) is switching the role in these examples? . It is not clear by tracing it down.
  • What will be the major key function need to address when we are switching between the roles.?
  • How we can assign the priority of our central and peripheral roles? I mean to say my priority here is let say peripheral role should be more important than central and when both called simultaneously than I want to perform my peripheral activity first.
Parents
  • Hello,

    As you mention, you can look at the examples in ble_central_and_peripheral for examples on how to set up a device that supports both the peripheral and central role. I think the hrs_rscs_relay is a place to start perhaps. I see that you are very concerned with the roles, peripheral and central, but in reality, there isn't really a switch saying whether you are currently a central or a peripheral. If you are advertising, then you are doing that as a peripheral, and if you are scanning, you are doing that as a central. You can start and stop the scanning from any events in your application. 

    When you are in a connection, the difference between central and peripheral will be smaller. The difference is what device that typically "owns" the services and characteristics, and hence, if you want to send a message to the other device, you need to know whether to send a notification or a write request (or something else). 

    How ble_conn_state_role(conn_handle) is switching the role in these examples? . It is not clear by tracing it down.

    This function will tell you whether you are a peripheral or central in that specific connection (the connection that this conn_handle belongs to).

    • What will be the major key function need to address when we are switching between the roles.?

    You don't really need to switch roles actively. You can start and stop advertising/scanning.

    How we can assign the priority of our central and peripheral roles? I mean to say my priority here is let say peripheral role should be more important than central and when both called simultaneously than I want to perform my peripheral activity first.

    What activities do you mean? You can handle both connections at the same time. Since the connections are time slotted, they will (most of the times) not collide. If they do collide, however, the Softdevice will handle scheduling dynamically, to maintain both connections. But I suspect this is not the type of priorities that you are talking about. Can you please elaborate?

    Best regards,

    Edvin

  •  


    Thank you for detail answer. That covers lot my confusion here. 

    Regarding priority if our softdevice is handling not to collide with communication between central and peripheral than I don't need to worry about it. 

    I see in the hrs_rscs_relay example most of the time it is remain in the BLE_GAP_ROLE_INVALID mode when not commnicating with other devices. that clears my doubt. 

    Let me try some troubleshoots over here and get back to you.

  • Without having confirmed this by testing, I guess that the conn_handle that you are checking is not a valid conn_handle, meaning it is not in a connection at all. The conn_handle is populated when you enter a connection, and then it is unpopulated in the disconnected event. 

    Vipul2988 said:
    Let me try some troubleshoots over here and get back to you

    I'll leave this one open, so just pop back if you have more related questions.

    BR,

    Edvin

  • Hi ,

    One question in my peripheral application we have used peer manager and in central application we did not used peer manager function. will it effect while it is communicating with central and peripheral both?

  • The peer manager is used to store bonding data with different devices. Bonding data are the encryption keys that are negotiated in the first connection, and they are stored and re-used the next time they connect, so that they do not have to generate new keys. It is also commonly used together with whitelisting, to allow only known devices to connect to the device. (like a wireless keyboard that will only accept connections from already known devices, unless you tell it specifically to look for new unknown connections). 

    It will not affect the connection (communication speed/priority) after the connection is initiated.

    BR,

    Edvin

Reply
  • The peer manager is used to store bonding data with different devices. Bonding data are the encryption keys that are negotiated in the first connection, and they are stored and re-used the next time they connect, so that they do not have to generate new keys. It is also commonly used together with whitelisting, to allow only known devices to connect to the device. (like a wireless keyboard that will only accept connections from already known devices, unless you tell it specifically to look for new unknown connections). 

    It will not affect the connection (communication speed/priority) after the connection is initiated.

    BR,

    Edvin

Children
Related