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

Can you Please try to add this to a true Cross platform package , like quick_blue #79

Closed
rohitsangwan01 opened this issue Mar 9, 2022 · 11 comments

Comments

@rohitsangwan01
Copy link
Contributor

rohitsangwan01 commented Mar 9, 2022

Hey , as title suggest , we dont really have true cross platform packages , there is one intresting package which currently supports
Windows , Mac , Android , Ios , it would be great if you can add support of linux to that package, quick_blue

@robert-ancell
Copy link
Contributor

I've been looking at integrating with flutter_reactive_ble but not making good progress. Thanks for the hint about quick_blue.

@rohitsangwan01
Copy link
Contributor Author

rohitsangwan01 commented Mar 17, 2022

@robert-ancell ,i checked your flutter_reactive_ble fork , and used that code for implementing bluez in quick_blue, almost added all methods but , connections seems to be unstable

getting this error while connecting : org.bluez.Error.Failed: Software caused connection abort
and after few tries device got connected , but then disconnected again

https://github.com/rohitsangwan01/quick_blue/tree/master/quick_blue_linux

@robert-ancell
Copy link
Contributor

That's awesome! I'll have a look and see if I can reproduce the same issues.

Because Bluetooth can sometimes be hard to debug I've found the best method is to try using bluetoothctl to confirm that you can access the device under test reliably. You can also use d-feet or the gdbus command line tool to access the D-Bus API directly to confirm if the issue is in BlueZ or our usage of the API.

@robert-ancell
Copy link
Contributor

There might be an issue here:

  void connect(String deviceId) async {
    await initBluez();
    final device = _getDeviceWithId(deviceId);
    if (device == null) {
      throw 'No such device $deviceId';
    } else {
      device.connect();
      _checkDeviceConnectionState(device);
    }
  }

You probably want to wait for the result of the connect call:

  Future<void> connect(String deviceId) async {
    await initBluez();
    final device = _getDeviceWithId(deviceId);
    if (device == null) {
      throw 'No such device $deviceId';
    } else {
      await device.connect();
      _checkDeviceConnectionState(device);
    }
  }

This also relies on the property changes being sent before the 'connect' completes. I think that should be the case but _checkDeviceConnectionState could potentially be using older data.

@rohitsangwan01
Copy link
Contributor Author

rohitsangwan01 commented Mar 18, 2022

@robert-ancell thanks , i will try this
Can we subscribe to characteristics ??
And get data as a stream
and Also ,can we change Mtu size
These two things are pending in implementation

@robert-ancell
Copy link
Contributor

robert-ancell commented Mar 18, 2022

I've just released bluez 0.7.8 which has support for subscription (use BlueZGattCharacteristic.startNotify and subscribe for changes to the 'Value` property. I'm working on getting data as a stream and MTU support at the moment.

@rohitsangwan01
Copy link
Contributor Author

@robert-ancell great will try with this update

@rohitsangwan01
Copy link
Contributor Author

rohitsangwan01 commented Mar 18, 2022

@robert-ancell are we suppose to read "Value" property in loop after using c.startNotify ??
c.value is a Future list , so how to subscribe for changes , or do we have to start timer or something to read new values in loop

@robert-ancell
Copy link
Contributor

robert-ancell commented Mar 20, 2022

You want something like this:

characteristic.propertiesChanged.listen((names) {
  if (names.contains ('Value')) {
    handleValue(characteristic.value);
  }
});
handleValue(characteristic.value);
characteristic.startNotify();

But we should really add a helper method to automatically make a stream for this.

@robert-ancell
Copy link
Contributor

See the BlueZ documentation for more information on the GATT API.

Over time I would like to see bluez.dart improved so that you don't have to refer to that, but for now that might be the easiest way to work out how to use the API.

@rohitsangwan01
Copy link
Contributor Author

ohh i see , Got it, thanks for info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants