Giter Club home page Giter Club logo

Comments (6)

jeroen1602 avatar jeroen1602 commented on August 20, 2024

You might be running in to the bug where the event that listens to value change event has a typo in it (I still need to release a new version for that)

Try readValue() to see if it can read a value at all.

Edit: you can also try and import the package from the git directly. https://flutter.dev/docs/development/packages-and-plugins/using-packages

from flutter_web_bluetooth.

thefakhreddin avatar thefakhreddin commented on August 20, 2024

@jeroen1602
Hi, thank you for your response.
I tried readValue() in my code and it threw the error:
Operation not supported for uuid 0000fff1-0000-1000-8000-00805f9b34fb
which is a valid uuid that I've tested before.

ByteData element = await readCharacteristic
            .readValue(timeout: Duration(seconds: 5));

I also removed the package from pubspec.yaml and tried to get the latest version from the repo directly:

flutter_web_bluetooth:
    git:
      url: git://github.com/jeroen1602/flutter_web_bluetooth.git

and I got the same result.

Am I missing anything?

from flutter_web_bluetooth.

jeroen1602 avatar jeroen1602 commented on August 20, 2024

Some operations are not supported based on how the characteristic is set up. You should be able to check what is supported by reading the properties of the characteristic.

But did you also try startNotifications() again with the version directly from GitHub? Because that one should work with the GitHub version.

from flutter_web_bluetooth.

thefakhreddin avatar thefakhreddin commented on August 20, 2024

@jeroen1602
Hi, Sorry for the delay!
I downloaded the package from the repo again and monitored the characteristic's properties (the ones I thought might be relevant) with the following code:

if (readCharacteristic != null) {
        print(
            "is notifying: ${readCharacteristic.isNotifying}");
        print(
            "notify: ${readCharacteristic.properties.notify}");
        print(
            "reliableWrite: ${readCharacteristic.properties.reliableWrite}");
        print("read: ${readCharacteristic.properties.read}");
      }

and here are the results:

is notifying: true
notify: true
reliableWrite: false
read: false

Couple of notes:

  1. I called startNotifications() right after declaring the characteristic. The print("is notifying: ${readCharacteristic.isNotifying}"); returns true which I thinkg verifies that.
  2. I previously used this exact characteristic via NRF connect application and flutter blue package before reading from my Bluetooth device. So I'm confident about the UUIDs that I chose. (getCharacteristic() method also did not throw NotFoundError and I confirmed the characteristic by printing its UUID print(readCharacteristic.uuid);)

from flutter_web_bluetooth.

JooYoo avatar JooYoo commented on August 20, 2024
  • ✅ With the following code, I'm able to .readValue() from device on Desktop Chrome. So the uuid is correct and working.
// Setup serviceId
final services = await _device?.discoverServices();
final service = services?.firstWhere(
  (service) => service.uuid == serviceId,
);
// Setup charId
final characteristic = await service?.getCharacteristic(characteristicUuid);
// Read from device
final res = characteristic?.readValue();
  • 💔 However, on mobile phone Android Chrome, search, connect, write are all working, but read value failed. I got the similar error from the android Chrome. Which is very strange, why it works on Desktop Chrome, but not on MobilePhone Android Chrome...
image

from flutter_web_bluetooth.

jeroen1602 avatar jeroen1602 commented on August 20, 2024

@JooYoo This seems to be a bug with the chrome version that is running on Android. You can avoid this error by checking it the characteristic supports reading with characteristic.properties.read. Though this doesn't explain why it would work on desktop chrome and not on the mobile version of chrome.

You could try enabling the enable-experimental-web-platform-features flag in chrome://flags, and see if that solves the problem.

You could also try using a BLE app on your phone to see if that is able to read from the characteristic, it may just be the Bluetooth implementation on the phone.

from flutter_web_bluetooth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.