Closed ghost closed 7 months ago
what are the exact bytes you get on iOS vs Android?
TBH, this is very unlikely to be a problem in FBP, and most likely a problem with you device or other code.
closing. no response.
Hi, sorry for the delay, I've just wanted to be sure. It seems something about the characteristics inside the code. You can find the bytes in the last rows of the code added above.
�� R����{�������
[246, 238, 32, 82, 169, 26, 151, 245, 123, 232, 202, 3, 240, 128, 140, 238]
The BLE device has a properly characteristic dedicated to write commands and an other one dedicated to sending the bytes to be read.
Is it correct if I use a characteristic as a variable in my provider class?
Future readCharacteristicInit() async {
try {
BluetoothService service = services.firstWhere(
(service) => service.characteristics.any((chr) =>
listEquals(chr.characteristicUuid.bytes, "2b2a".convertToIntList)),
orElse: () {
throw Exception("This device has not a read data dedicated service.");
});
readChr = service.characteristics.firstWhere((chr) => listEquals(
chr.characteristicUuid.bytes,
"2b2a".convertToIntList,
));
await readChr!.setNotifyValue(true);
readChrDataStream = readChr!.lastValueStream.listen((data) {
try {
logger.info("[READ] ${utf8.decode(data)}");
} catch (e) {
logger.warning("Error while parsing data from Read Chr.");
logger.info(data);
}
});
if (readChrDataStream != null)
device.cancelWhenDisconnected(readChrDataStream!);
logger.info("Read chr configured successfully.");
notifyListeners();
} on Exception catch (e) {
logger.shout(e);
}
}
Future writeCharacteristicInit() async {
try {
BluetoothService service = services.firstWhere(
(service) => service.characteristics.any((chr) =>
listEquals(chr.characteristicUuid.bytes, "2b2e".convertToIntList)),
orElse: () {
throw Exception("This device has not a write command dedicated service.");
});
writeChr = service.characteristics.firstWhere((chr) => listEquals(
chr.characteristicUuid.bytes,
"2b2e".convertToIntList,
));
logger.info("Write chr configured successfully.");
notifyListeners();
} on Exception catch (e) {
logger.shout(e);
}
}
Future sendCommand(String command) async {
if (writeChr != null) {
try {
await writeChr!.write(
utf8.encode(command),
withoutResponse: writeChr!.properties.writeWithoutResponse,
allowLongWrite: true,
);
logger.info("Write: $command");
if (Platform.isAndroid) {
await readChr!.read();
}
} catch (e) {
logger.shout(ExceptionExtension.printException("Write error error", e));
}
}
}
Requirements
Have you checked this problem on the example app?
Yes
FlutterBluePlus Version
1.32.1
Flutter Version
3.19.3
What OS?
Android
OS Version
Android 11
Bluetooth Module
Espressif ESP32C3_DevkitC-02v1.1
What is your problem?
When listening to the onValueReceive byte stream, in Android I receive the wrong bytes that cannot be decoded with utf8 or json, in iOS I do. I receive a different array of bytes in response even though the command sent is the same.
Logs