dotintent / FlutterBleLib

Bluetooth Low Energy library for Flutter with support for simulating peripherals
Apache License 2.0
531 stars 195 forks source link

Is setting interval after connection possible? #564

Open emretufekci opened 3 years ago

emretufekci commented 3 years ago

After connection, i can see interval: 56 etc. i would like to reduce/increase this value, is it possible via FlutterBleLib library?

emretufekci commented 3 years ago

I found this from java code:

        int connectionPriorityBalanced = 0; //BluetoothGatt.CONNECTION_PRIORITY_BALANCED
        bleAdapter.connectToDevice(deviceId,
                new ConnectionOptions(isAutoConnect, requestMtu, refreshGattMoment, timeoutMillis, connectionPriorityBalanced),
                new OnSuccessCallback<Device>() {
                    @Override
                    public void onSuccess(Device data) {
                        safeMainThreadResolver.onSuccess(null);
                    }
                },
                new OnEventCallback<ConnectionState>() {
                    @Override
                    public void onEvent(final ConnectionState data) {
                        streamHandler.onNewConnectionState(new ConnectionStateChange(deviceId, data));
                    }
                }, new OnErrorCallback() {
                    @Override
                    public void onError(final BleError error) {
                        safeMainThreadResolver.onError(error);
                    }
                });
    }

This BluetoothGatt.CONNECTION_PRIORITY_BALANCED part should be adaptive instead of constant value. This solves the issue and we can make connection priority request so it would be affect connection interval. ASAIK specifying connection interval directly is not possible but we can offer connection prority to tell peripheral and if it's possbile slave & master handshakes on this period.

I might be plan to make pull request for this if the library owners is allows or we can keep the issue for tracking.