bmentink
12/04/2025, 9:21 PMfloitsch
12/04/2025, 9:22 PMbmentink
12/04/2025, 9:24 PMfloitsch
12/04/2025, 9:31 PMbmentink
12/04/2025, 9:31 PMfloitsch
12/04/2025, 9:32 PMfloitsch
12/04/2025, 9:32 PMbmentink
12/04/2025, 9:32 PMfloitsch
12/04/2025, 9:33 PMbmentink
12/04/2025, 9:34 PMbmentink
12/04/2025, 9:36 PMfloitsch
12/04/2025, 9:36 PMfloitsch
12/04/2025, 9:37 PMfloitsch
12/08/2025, 10:36 AMMichaelK
12/08/2025, 11:40 AMfinal Uuid serviceUuid = Uuid.parse('6e40fff0-b5a3-f393-e0a9-e50e24dcca9e');
final Uuid writeCharUuid = Uuid.parse('6e400002-b5a3-f393-e0a9-e50e24dcca9e');
final Uuid readCharUuid = Uuid.parse('6e400003-b5a3-f393-e0a9-e50e24dcca9e');
final FlutterReactiveBle _ble = FlutterReactiveBle();
void _initializeNotifications() {
final QualifiedCharacteristic readChar = QualifiedCharacteristic(
serviceId: serviceUuid,
characteristicId: readCharUuid,
deviceId: _deviceId!,
);
_notifySub = _ble
.subscribeToCharacteristic(readChar)
.listen(
(data) {
final Uint8List bytes = Uint8List.fromList(data);
_handleIncomingData(bytes);
},
onError: (Object error) {
print('Notification error: $error');
},
);
requestBatteryLevel();
}
Future<void> requestBatteryLevel() async {
sendRequest('Battery Level', [cmdBattery]);
}floitsch
12/08/2025, 11:49 AMwriteCharUuid and readCharUuid).
You can then write-characteristic.write data (where data is your 16-byte? message).
For reading:
task::
read-characteristic.subscribe
while true:
incoming-data := read-characteristic.wait-for-notification
// Use the data.MichaelK
12/08/2025, 12:57 PMfloitsch
12/08/2025, 12:58 PMread-characteristic.unsubscribe and then break to get out of the loop.
Or, if you only need one notification, don't even write the loop.
read-characteristic.subscribe
incoming-data := read-characteristic.wait-for-notification
read-characteristic.unsubscribe
If it's an RPC and you only do one RPC call, you can probably even avoid the task:
read-characteristic.subscribe
write-characteristic.write #[some-message]
incoming := read-characteristic.wait-for-notification
read-characteristic.unsubscribekasperl
12/08/2025, 12:58 PMMichaelK
12/08/2025, 1:02 PMfloitsch
12/08/2025, 1:06 PMfinally to unsubscribe:
reader-task := task::
ch.subscribe
try:
while true:
incoming := ch.wait-for-notification
finally:
ch.unsubscribe
...
// Cleanup.
reader-task.cancelkasperl
12/08/2025, 1:07 PMTask.group? You can set it up so that if one task completes, the other is stopped.MichaelK
12/08/2025, 1:08 PMfloitsch
12/08/2025, 1:09 PMMichaelK
12/08/2025, 1:10 PMow-peter
12/09/2025, 2:45 PMfloitsch
12/09/2025, 2:50 PMow-peter
12/09/2025, 2:53 PMfloitsch
12/09/2025, 2:54 PMaddshore
12/11/2025, 1:31 PM