Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

after disconnecting from an earable, it is not possible to reconnect #55

Open
TobiasRoeddiger opened this issue Jan 23, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@TobiasRoeddiger
Copy link
Member

connect to OpenEarable, then tap on it to disconnect. it is no longer possible to connect again


reported by @kkai on iOS

@TobiasRoeddiger TobiasRoeddiger added the bug Something isn't working label Jan 23, 2024
@o-bagge
Copy link
Collaborator

o-bagge commented Jan 25, 2024

The problem is with the _retryConnection method in open_earable_flutter (ble_manager.dart line 65). I moved the recursive function call into the switch case and it seems to solve the problem. Why do we need multiple retries @DennisMoschina ?

StreamSubscription? _retryConnection(int retries, DiscoveredDevice device) {
    if (retries <= 0) {
      _connectingDevice = null;
      return null;
    }
    return _flutterReactiveBle.connectToAdvertisingDevice(
        id: device.id,
        prescanDuration: const Duration(seconds: 1),
        withServices: [sensorServiceUuid]).listen((event) async {
      switch (event.connectionState) {
        case DeviceConnectionState.connected:
          _connectedDevice = device;
          _flutterReactiveBle.requestMtu(deviceId: device.id, mtu: mtu);
          if (deviceIdentifier == null || deviceFirmwareVersion == null) {
            await readDeviceIdentifier();
            await readDeviceFirmwareVersion();
          }
          _connectionStateController.add(true);
          _connectingDevice = null;
          return;
        case DeviceConnectionState.disconnected:
          _connectedDevice = null;
          _connectingDevice = null;
          _deviceFirmwareVersion = null;
          _deviceIdentifier = null;
          _connectionStateController.add(false);
          _connectionStateSubscription = _retryConnection(retries - 1, device);
        default:
      }
      // _connectionStateSubscription = _retryConnection(retries - 1, device);  <---- moved this line up
    });
  }

@DennisMoschina
Copy link
Collaborator

Why do we need multiple retries

On Android we somehow could only connect after multiple retries so I added the _retryConnection method as a quick fix

@o-bagge
Copy link
Collaborator

o-bagge commented Jan 27, 2024

Ok makes sense. Do you think it will still work on android with this change?

@TobiasRoeddiger
Copy link
Member Author

@cadivus is this problem resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants