Open thefakhreddin opened 2 years ago
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
@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?
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.
@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:
startNotifications()
right after declaring the characteristic. The print("is notifying: ${readCharacteristic.isNotifying}");
returns true which I thinkg verifies that.getCharacteristic()
method also did not throw NotFoundError
and I confirmed the characteristic by printing its UUID print(readCharacteristic.uuid);
).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();
@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.
Hi, After going through a ton of effort, I'm still unable to read data. Please help! I'm using this simple code to read data from a characteristic but the
value
stream seems to be empty.I printed out the readCharacteristic.uuid to make sure that the characteristic is recognized properly. But when I'm expecting to receive data immediately, after 10 seconds the timeout exceeds and I catch a timeout error which I suppose indicates that the stream was empty until that time. If I'm being correct, at least my terminal should have prompted the properties of whatever ByteData is being received.
I have also tried
.lastValue
.To make sure that my transmitter device is indeed transmitting, I successfully read data using two other platforms using a similar method.
Regards.