I'm trying to open a Bluetooth LE connection with a device using the flutter_blue library. Everthing is working fine, except that the method connect always reaches timeout.
final device = await startScanAndListenForDevice();
print('NORDIC -> Found device. Analysing ...');
print('NORDIC -> Found JT Tag device. Relevant info:');
print('NORDIC -> - id : ${device.id}');
print('NORDIC -> - type : ${device.type}');
print('NORDIC -> - name : ${device.name}');
print('NORDIC -> Connecting ...');
// Check if device is already connected
try {
// Hangs here
await device.connect(autoConnect: true, timeout: const Duration(seconds: 30));
} on PlatformException catch (e) {
if (e.code != 'already_connected') {
print('NORDIC -> Failed to connect: $e');
return null;
}
print('NORDIC -> Already connected. Ignoring.');
} on Exception catch (e) {
print('NORDIC -> Failed to connect: $e');
return null;
}
// Code to run after connection
...
Here is the output:
I/flutter (30273): NORDIC -> Found device 38:9A:F6:25:BC:DC/Galaxy J5 Prime
I/flutter (30273): NORDIC -> Bluetooth scan cleared
I/flutter (30273): NORDIC -> Closing stream
I/flutter (30273): NORDIC -> Found device. Analysing ...
I/flutter (30273): NORDIC -> Found JT Tag device. Relevant info:
I/flutter (30273): NORDIC -> - id : 38:9A:F6:25:BC:DC
I/flutter (30273): NORDIC -> - type : BluetoothDeviceType.classic
I/flutter (30273): NORDIC -> - name : Galaxy J5 Prime
I/flutter (30273): NORDIC -> Connecting ...
D/BluetoothManager(30273): getConnectedDevices
D/BluetoothGatt(30273): connect() - device: 38:9A:F6:25:BC:DC, auto: true
D/BluetoothGatt(30273): registerApp()
D/BluetoothGatt(30273): registerApp() - UUID=d490238f-6fd1-4d5b-805b-6ad0ff46a260
D/BluetoothGatt(30273): onClientRegistered() - status=0 clientIf=7
D/BluetoothAdapter(30273): isLeEnabled(): ON
D/BluetoothLeScanner(30273): could not find callback wrapper
D/BluetoothManager(30273): getConnectionState()
D/BluetoothManager(30273): getConnectedDevices
... timeout ...
OBS: I tested using the real device with Bluetooth LE, my notebook, and another smartphone and the error is always the same. This log was generated trying to connect to another smartphone (Android). Also, the device is working, I tested it using some third party bluetooth tool and it was able to receive some data.