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

Parents
  • 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.

  • Great! Then I would appreciate if you could accept my answer by clicking the grey circle with a check mark in it, next to my answer. For more information, please take our tour.

Reply Children
No Data
Related