I'm working on a project about two BLE device: one, which streams inertial data, acts as peripheral and the other, which is a custom USB dongle, acts as central device. To stream data between theese devices I activated the notify feature with 2M PHY and max data length parameters to maximize throughput. Now I noticed that the peripheral send data with an minimum fixed interval: the time between the call of bt_gatt_notify_cb and the call of the bt_gatt_notify_params.func is 100ms.
static void Ble_Connection_Inertial_Data_Tx_On_Sent( struct bt_conn *conn, void *user_data ) { ARG_UNUSED( user_data ); k_sem_give( &inertialTxSemaphore ); } static void Ble_Connection_Inertial_Data_Tx_Thread( void ) { static fifo_inertial_data_item_t *fifoItem; static struct bt_gatt_notify_params params = { 0 }; static const struct bt_gatt_attr *attr; static uint8_t sampleCount = 0; static uint8_t inertialPacket[ INERTIAL_SAMPLE_PER_FRAME_BYTE_SIZE_MAX ]; for ( int i = 0; i < remoteSrv.attr_count; i++ ) { if ( bt_uuid_cmp( remoteSrv.attrs[ i ].uuid, BT_UUID_INERTIAL_DATA_TX_CHRC ) == 0 ) { LOG_INF( "Found inertial arrts at %d", i ); attr = &remoteSrv.attrs[ i ]; break; } } params.attr = attr; params.func = Ble_Connection_Inertial_Data_Tx_On_Sent; for ( ;; ) { fifoItem = k_fifo_get( &inertialDataTxFifo, K_FOREVER ); memcpy( inertialPacket + ( sampleCount * INERTIAL_SAMPLE_BYTE_SIZE ), fifoItem->data, fifoItem->length ); sampleCount++; if ( sampleCount >= samplePerFrame ) { sampleCount = 0; if ( notificatioInertialDataTxEnabled == BT_NOTIFICATION_ENABLED ) { params.data = inertialPacket; params.len = samplePerFrame * INERTIAL_SAMPLE_BYTE_SIZE; if ( k_sem_take( &inertialTxSemaphore, K_MSEC( 150 ) ) != 0 ) { LOG_WRN( "\n[W] DEVICE - Send inertial data timeout" ); continue; } if ( bt_gatt_notify_cb( currentConnection, ¶ms ) != 0 ) { LOG_WRN( "\n[W] DEVICE - Gatt notify failed" ); k_mutex_lock( &appDataMutex, K_FOREVER ); appData.deviceInError = true; k_mutex_unlock( &appDataMutex ); } } } } }
My doubts:
Is this delay due to the connection interval parameter?
How should I set the interval connection? I read about to simply define MIN_CONN_INTERVAL and MAX_CONN_INTERVAL in the BLE source code. Is it the best way?
If I want to set the connection interval, I need to do it on both the devices (central and peripheral)? Which device define theese connection parameters?