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

How can I subscribe to a characteristic #1

Open
ycy2019 opened this issue Feb 26, 2024 · 4 comments
Open

How can I subscribe to a characteristic #1

ycy2019 opened this issue Feb 26, 2024 · 4 comments

Comments

@ycy2019
Copy link

ycy2019 commented Feb 26, 2024

I have a bluetooth bracelet and I want the app to receive a message and send a network request in time when the bracelet is tapped, but I don't see the ability to do so in the api

@isaaclkh
Copy link

I might be wrong, but I think this package only provides one time reading (not in stream, so there's no subscribe function).
Maybe, you need to use other packages to connect, read, and write (like flutter blue plus) in stream.

And to make it work on the background service, you need to use other packages.
(You can try using https://pub.dev/packages/flutter_foreground_task or possibly https://pub.dev/packages/flutter_isolate).

@ghousmuh934
Copy link
Collaborator

It will check automatically through this line "char.properties.notify == true". If selected characteristic has notified property, then it will subscribe to it and start getting values otherwise, it will only read one time and return the value. So, it depends upon the characteristic either it has notified property or not.

@ChaseGuru
Copy link

I'm a bit confused by that to be honest. It returns a Future<String?> - which I would have assumed included the needed data.

But given your comment I decided to go check the source code. The android project had basically no code. But checking the dart code better, I assume the functionality is done mostly through flutter packages.

lib/flutter_blue_background.dart@readData for android seems to add a readData and characteristic string to the read data preferences string list. Sort of weird but ok.

Connect to device seems also seems to have some non-configurable android notification channel settings that should probably be configurable.

Then, the lib/ble_background_service seems to have scanningMethod which when it finds a matching device will call "receiveCommandFromFirmware" which in turn - if it finds a matching characteristic will add to the strings log when the characteristic is written to.

So that might work, particularly if there's a way to subscribe to a shared preffs string log (kind of annoying and potentially latent if we have to read it on loop).

However, on iOS, it doesn't seem to do any notifiy check, it just calls some ios code which just calls read and returns a result.

@ChaseGuru
Copy link

In summary, it seems like this plugin may not be fully fleshed for purposes like constantly staying connected and getting notified of it's events. And it may have some changes that are probably important for configuration (like the android service).

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

4 participants