I am developing an simple app for reading and writing Bluetooth data using Flutter and Android Studio with flutter_blue_plus lib.
But why can I write but not read?
After writing, read immediately.
The write and read code and error messages are below.
The same error occurs even if you change the order of read and write.
++++++++++
code
bleBuilder!.writeData();
bleBuilder!.readData();
void writeData() {
String serviceUUID = accDataCharacteristic!.serviceUuid.toString();
String sUUID = accDataCharacteristic!.uuid.toString();
String characterUUID = accDataCharacteristic!.characteristicUuid.toString();
print('writeData serviceUUID '+ serviceUUID + ' sUUID '+ sUUID + ' characterUUID '+ characterUUID);
accDataCharacteristic?.write([51, 52, 99, 100]);
}
void readData(){
String serviceUUID = accDataCharacteristic!.serviceUuid.toString();
String sUUID = accDataCharacteristic!.uuid.toString();
String characterUUID = accDataCharacteristic!.characteristicUuid.toString();
print('readData serviceUUID '+ serviceUUID + ' sUUID '+ sUUID + ' characterUUID '+ characterUUID);
+++++++++++++++
error
I/flutter (11323): floatingActionButton onPressed
I/flutter (11323): writeData serviceUUID 6e400001-b5a3-f393-e0a9-e50e24dcca9e sUUID 6e400002-b5a3-f393-e0a9-e50e24dcca9e characterUUID 6e400002-b5a3-f393-e0a9-e50e24dcca9e
I/flutter (11323): readData serviceUUID 6e400001-b5a3-f393-e0a9-e50e24dcca9e sUUID 6e400002-b5a3-f393-e0a9-e50e24dcca9e characterUUID 6e400002-b5a3-f393-e0a9-e50e24dcca9e
I/flutter (11323): readData Instance of 'Future<List<int>>'
I/flutter (11323): Instance of 'Future<List<int>>'
I/flutter (11323): [FBP] <writeCharacteristic> args: {remote_id: D4:EC:FA:03:64:55, service_uuid: 6e400001-b5a3-f393-e0a9-e50e24dcca9e, secondary_service_uuid: null, characteristic_uuid: 6e400002-b5a3-f393-e0a9-e50e24dcca9e, write_type: 0, allow_long_write: 0, value: 33346364}
D/[FBP-Android](11323): [FBP] onMethodCall: writeCharacteristic
D/[FBP-Android](11323): [FBP] onCharacteristicWrite:
D/[FBP-Android](11323): [FBP] chr: 6e400002-b5a3-f393-e0a9-e50e24dcca9e
D/[FBP-Android](11323): [FBP] status: GATT_SUCCESS (0)
I/flutter (11323): [FBP] <writeCharacteristic> result: true
I/flutter (11323): [FBP] [[ OnCharacteristicWritten ]] result: {error_string: GATT_SUCCESS, service_uuid: 6e400001-b5a3-f393-e0a9-e50e24dcca9e, success: 1, remote_id: D4:EC:FA:03:64:55, error_code: 0, characteristic_uuid: 6e400002-b5a3-f393-e0a9-e50e24dcca9e, value: 33346364}
I/flutter (11323): [FBP] <readCharacteristic> args: {remote_id: D4:EC:FA:03:64:55, service_uuid: 6e400001-b5a3-f393-e0a9-e50e24dcca9e, secondary_service_uuid: null, characteristic_uuid: 6e400002-b5a3-f393-e0a9-e50e24dcca9e}
D/[FBP-Android](11323): [FBP] onMethodCall: readCharacteristic
I/gralloc4(11323): @set_metadata: update dataspace from GM (0x00000000 -> 0x08010000)
E/flutter (11323): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(readCharacteristic, The READ property is not supported by this BLE characteristic, null, null)
E/flutter (11323): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7)
E/flutter (11323): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
E/flutter (11323): <asynchronous suspension>
E/flutter (11323): #2 FlutterBluePlus._invokeMethod (package:flutter_blue_plus/src/flutter_blue_plus.dart:603:13)
E/flutter (11323): <asynchronous suspension>
E/flutter (11323): #3 BluetoothCharacteristic.read (package:flutter_blue_plus/src/bluetooth_characteristic.dart:130:7)
E/flutter (11323): <asynchronous suspension>
I am using the flutter_blue_plus library and am referring to the example app.
New contributor
t h is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.