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

How to send some data from multilink peripheral to multilink central?

I have three pca10001 boards. One is programmed as multilink central and other is programmed as multilink peripheral. when both peripherals are connected to central, the central detects them both seperately but shows the same device id of both the peripherals which is I dont want. I want to see different device ids of peripherals. . so I lea

  • I'm having trouble understanding you. Could you include some code that shows what you are doing? By device id, do you mean the index in m_client? And by status do you mean if the LED number index is on or off? Or the state?

  • image description In main.c file of multilink_Cenral. first i defined global variables..

    image description then i assigned my global variables values of p_peer_addrs.

    image description now i am in the file of client_handling.c .. i defined those variables as extern in it.

    image description finally i printed the variables which contain the device id.. with 1 and 0. if led is on, the output is something like this, 5BE4=1 , and when LED is off, the output is 5BE4=0. for one board as a peripheral it is perfect.

    the problem is when I connect the two boards as peripheral, i get the same device id of both which is not I want.. I want different device id of both..

  • I hope you will get it now.. I want the different device ids.. or something unique data which distinguish both the peripherals.. please help

  • Ok. So device ID is the address. You have only defined one set of variables in main.c. You will get the DM_EVT_CONNECTION twice. Once on connection with the first device, its address will be set to your set of variables. Second on connection with the second device, its address will overwrite your set of variables. You need two sets of variables if you have two devices and set one address to each of them. As you have understood the address is not included in the BLE_GATTC_EVT_HVX event, so you need some other way of identifying which device address the event belongs to. As you can see in client_handling_ble_evt_handler() it uses client_find(p_ble_evt->evt.gattc_evt.conn_handle) to find the index, i.e. which device/client the event comes from. It accomplishes this by comparing the connection handle of the event with the connection handles in m_client[i].srv_db.conn_handle. Connection handle is what you should use to identify which device the event belongs to, so you should also tie the connection handles to the devices addresses.

    You could:

    1. Declare a struct with a set of variables to store the address and one variable to store the connection handle. Or use some other way to tie the connection handle to the device address.
    2. Add two defines of this struct. When you get the first DM_EVT_CONNECTION you add the address and the connection handle to one of them, when you get the second you add the address and the connection handle to the other.
    3. Then in on_evt_hvx() or somewhere else, you compare the connection handle of the event to the connection handles in your two structs. If you get a match you print out the address, and the status of the LED contained in p_ble_evt->evt.gattc_evt.params.hvx.data[0].

    You don't have to this through client_handling_ble_evt_handler() you can add your own event handler in ble_evt_dispatch() in main.c and then do everything there, or do it directly in ble_evt_dispatch(). The events from the SoftDevice are sent to all the events handlers in ble_evt_dispatch().

    Many ways of solving this, but the main point is that you need to use the connection handle to identify the client/device.

  • please tell me, how to compare connection handles in on_evt_hvx() in client_handling.c ??

Related