Skip to content

Unable to read data using .value property from a BluetoothCharacteristic object. #13

@thefakhreddin

Description

@thefakhreddin

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.


readCharacteristic = await services
                  .firstWhere((service) => service.uuid == SERVICE_UUID)
                  .getCharacteristic(READ_UUID);

print("read characteristic: ${readCharacteristic.uuid}");
await readCharacteristic.startNotifications();
try {
  await readCharacteristic.value
      .timeout(Duration(seconds: 5))
      .firstWhere((element) {
    print("buffer: ${element.buffer}");
    print("elementSizeInBytes: ${element.elementSizeInBytes}");
    print("lengthInBytes: ${element.lengthInBytes}");
    print("offsetInBytes: ${element.offsetInBytes}");
    return false;
  });
} catch (e) {
  print("err: $e");
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions