Dear Sir/Madam
I am using multiperipheral example. I can connect to multiple phones. I added NUS example in it.
I am using package nRF5_SDK_15.2.0_9412b96.
I do not know how to assign connection handle to NUS when a device connects. I initialised NUS in services_Init().
static void services_init(void)
{
uint32_t err_code;
ble_nus_init_t nus_init;
//ble_nus_init_t nus_init[LINK_TOTAL];
static uint8_t m_ble_nus_c_count;
nrf_ble_qwr_init_t qwr_init = {0};
// Initialize Queued Write Module.
qwr_init.error_handler = nrf_qwr_error_handler;
//for muliuple link
for (uint32_t i = 0; i < LINK_TOTAL; i++)
{
err_code = nrf_ble_qwr_init(&m_qwr[i], &qwr_init);
APP_ERROR_CHECK(err_code);
}
// Initialize NUS.
memset(&nus_init, 0, sizeof(nus_init));
nus_init.data_handler = nus_data_handler;
err_code = ble_nus_init(&m_nus, &nus_init);
APP_ERROR_CHECK(err_code);
}
When I get a data from phone, I can receive it in the code and display in terminal but I do not which connection handle is sending data as I do not know how to assign the handles to NUS and where should I do it.
Connection handles are created when ble_evt_handler is triggered.
printf("Connection with link 0x%x established.", p_ble_evt->evt.gap_evt.conn_handle);
// Assign connection handle to available instance of QWR module.
for (uint32_t i = 0; i < NRF_SDH_BLE_PERIPHERAL_LINK_COUNT; i++)
{
// ble_nus_c_evt.conn_handle = p_ble_evt->evt.gattc_evt.conn_handle;
if (m_qwr[i].conn_handle == BLE_CONN_HANDLE_INVALID)
{
err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr[i], p_ble_evt->evt.gap_evt.conn_handle);
APP_ERROR_CHECK(err_code);
// err_code = ble_nus_c_handles_assign(p_ble_evt->evt.gap_evt.conn_handle); //I thought I should do this, but it creates error
// APP_ERROR_CHECK(err_code);
break;
}
}
When I receive data, I try to enquire its conn_handle but it was always empty.