Hi,
I am using nRF52840 with SDK 15.3.0 and S140.
I am connecting to multiple peripherals as a central device and using NUS to communicate with these peripherals. I need to keep track of peripherals within my own array (scan_xtag_arr[]). I am using the BLE_NUS_C_ARRAY_DEF and BLE_DB_DISCOVERY_ARRAY_DEF() macros after referencing the ble_app_multilink_central example. BLE_NUS_C_ARRAY_DEF is defining my m_ble_nus_c_arr[].
After successfully connecting peripherals and discovering the NUS service on each, I receive a BLE_NUS_C_EVT_DISCOVERY_COMPLETE event within my NUS event handler called xgw_ble_nus_c_evt_handler(). Within this handler, I am setting the handles within the m_ble_nus_c_arr[] index to match my scan_xtag_arr[] index for the peripheral.
So, I connect peripheral_A and setup conn_handle 0 (provided as p_ble_nus_evt->conn_handle within the NUS handler) within m_ble_nus_c_arr[0] using ble_nus_c_handles_assign(). I connect peripheral_B and setup conn_handle 1 within m_ble_nus_c_arr[1]. So far no issue.
I send commands to both peripheral_A and peripheral_B and I get responses back as expected. Specifically, my NUS handler is passed event BLE_NUS_C_EVT_NUS_TX_EVT with p_ble_nus_c pointing at m_ble_nus_c_arr[0] and p_ble_nus_evt->conn_handle = 0 when getting responses from peripheral_A. Likewise, p_ble_nus_c points at m_ble_nus_c_arr[1] and p_ble_nus_evt->conn_handle = 1 when getting responses from peripheral_B. Still good.
Issues occur after I disconnect peripheral_B. I send a message to peripheral_A, and the response comes into my NUS handler (event BLE_NUS_C_EVT_NUS_TX_EVT) with p_ble_nus_c pointing at m_ble_nus_c_arr[1] (the disconnected peripheral m_ble_nus_c_arr[] element) and p_ble_nus_evt->conn_handle = 0xFFFF (denoting invalid handle). The actual data in the message from my peripehral_A is correct, just the references provided within the NUS handler (p_ble_nus_c and p_ble_nus_evt->conn_handle) are incorrect.
It looks like I am getting incorrect references passed back to the NUS event handler, even when I am able to send and receive data ok over NUS.
Is there another way that I can ref the individual NUS connections? Both NUS client pointer (p_ble_nus_c) and p_ble_nus_evt->conn_handle values passed to the NUS handler seem unreliable.
As a last resort, I can update the protocol running over NUS to determine the source of responses from peripherals, but this would be a hack to work around a Nordic API issue. There must be some way to properly reference which NUS connection is the source for incoming data as indicated by the BLE_NUS_C_EVT_NUS_TX_EVT event.
Thanks,
Mark J