Hello
I'm trying connect central to 4 peripheralPeripheral has 3 different customization services. When I connected to 4 peripheral, I encountered the problem of service collection not getting conn_handle like the conn_handle of discovery (deviceID in the image). I added a delay after every connected event of 200ms. But things are not satisfactory. The picture below shows the result I got from one service collection, and the other services have the same situation.
Collection service code of central
void ble_sensor_on_db_disc_evt(ble_sensor_t * p_sensor, const ble_db_discovery_evt_t * p_evt) { //read data:sensor, error, bas if (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE && p_evt->params.discovered_db.srv_uuid.uuid == VNETGPS_SENSOR_SERVICE_READ && p_evt->params.discovered_db.srv_uuid.type == p_sensor->uuid_type) { uint32_t i; ble_sensor_evt_t evt; evt.evt_type = BLE_SENSOR_EVT_DISCOVERY_COMPLETE; evt.conn_handle = p_evt->conn_handle; for (i = 0; i < p_evt->params.discovered_db.char_count; i++) { const ble_gatt_db_char_t * p_char = &(p_evt->params.discovered_db.charateristics[i]); switch(p_char->characteristic.uuid.uuid) { case VNETGPS_SENSOR_CHAR_SENSOR: { evt.sensor.sensor_db.char_handle = p_char->characteristic.handle_value; evt.sensor.sensor_db.sensor_cccd_handle = p_char->cccd_handle; } break; case VNETGPS_SENSOR_CHAR_MORE: { evt.more.more_db.char_handle = p_char->characteristic.handle_value; evt.more.more_db.more_cccd_handle = p_char->cccd_handle; } break; default: break; } } if (p_sensor->conn_handle != BLE_CONN_HANDLE_INVALID) { if ((p_sensor->peer_sensor_db.sensor_cccd_handle == BLE_GATT_HANDLE_INVALID) && (p_sensor->peer_sensor_db.char_handle == BLE_GATT_HANDLE_INVALID)) { p_sensor->peer_sensor_db = evt.sensor.sensor_db; } if ((p_sensor->peer_more_db.more_cccd_handle == BLE_GATT_HANDLE_INVALID) && (p_sensor->peer_more_db.char_handle == BLE_GATT_HANDLE_INVALID)) { p_sensor->peer_more_db = evt.more.more_db; } } p_sensor->evt_handler(p_sensor, &evt); } }
event ble of central
switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: // start discovery of services. // memset(&m_db_disc[p_gap_evt->conn_handle], 0, sizeof(m_db_disc[p_gap_evt->conn_handle])); NRF_LOG_INFO("Connected."); err_code = ble_db_discovery_start(&m_db_disc[p_gap_evt->conn_handle], p_gap_evt->conn_handle); nrf_delay_ms(BLE_DISCOVERY_TIME); if (err_code != NRF_ERROR_BUSY) { APP_ERROR_CHECK(err_code); } if (ble_conn_state_central_conn_count() < NRF_SDH_BLE_CENTRAL_LINK_COUNT) { scan_start(); } break; case BLE_GAP_EVT_DISCONNECTED: NRF_LOG_INFO("Disconnected."); if (ble_conn_state_central_conn_count() < NRF_SDH_BLE_CENTRAL_LINK_COUNT) { scan_start(); } break;
on peripheral
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(100, UNIT_1_25_MS) /**< Minimum acceptable connection interval (0.1 seconds). */ #define MAX_CONN_INTERVAL MSEC_TO_UNITS(200, UNIT_1_25_MS) /**< Maximum acceptable connection interval (0.2 second). */ #define SLAVE_LATENCY 0 /**< Slave latency. */ #define CONN_SUP_TIMEOUT MSEC_TO_UNITS(1000, UNIT_10_MS) /**< Connection supervisory timeout (4 seconds). */ #define FIRST_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(5000) /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */ #define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(30000) /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */ #define MAX_CONN_PARAMS_UPDATE_COUNT 3 /**< Number of attempts before giving up the connection parameter negotiation. */
I'm sorry, my english
P/s: when I connect each device, this problem does not occur.