First, thank you providing us this repo, it is very helpfull.
From central device with another device I perform a simple write to a characteristic (using flutter blue).
await char1.write(utf8.encode("Test"));
On Peripheral side I am expecting getting the value from callback with
BlePeripheral.setWriteRequestCallback((characteristicId, offset, value) {
Get.log("WriteRequest: $characteristicId : $offset : $value");
String? resultString = value != null ? utf8.decode(value) : null;
print(resultString);
print(value);
print(characteristicId);
}
But I get
I/flutter (27720): null
I/flutter (27720): null
I/flutter (27720): 00002a18-0000-1000-8000-00805f9b34fb
But when I trigger this function (from periphal side)
void updateCharacteristic() async {
for (var device in devices) {
try {
await BlePeripheral.updateCharacteristic(
deviceId: device,
characteristicId: characteristicTest,
value: utf8.encode("Test Data"),
);
} catch (e) {
Get.log("UpdateCharacteristicError: $e");
}
}
}
And then I try to perform a write again from central device, I got the date from the updateCharacterisc in the log each time I trigger the write, and not the null result again.. but still I don't get data from central.
I/flutter (29461): Test Data
I/flutter (29461): [84, 101, 115, 116, 32, 68, 97, 116, 97]
I/flutter (29461): 00002a18-0000-1000-8000-00805f9b34fb
I guess I am missing something here, how could I get within the peripheral the data sent with write from a central device ?
Thank