Unless I am mistaken, the following code only allows one notification to be active at a time:
/// Notifies when the characteristic's value has changed.
/// setNotification() should be run first to enable them on the peripheral
Stream<List<int>> onValueChanged(BluetoothCharacteristic characteristic) {
return FlutterBlue.instance._characteristicNotifiedChannel
.receiveBroadcastStream()
.map((buffer) => new protos.OnNotificationResponse.fromBuffer(buffer))
.where((p) => p.remoteId == id.toString())
.map((p) => new BluetoothCharacteristic.fromProto(p.characteristic))
.where((c) => c.uuid == characteristic.uuid)
.map((c) {
characteristic.updateDescriptors(c.descriptors);
characteristic.value = c.value;
return c.value;
});
}
For many BLE devices it is necessary to listen to notifications from multiple characteristics at the same time. Not to mention from multiple devices!
This allows for multiple characteristics, since they are being filtered first by device ID and then by characteristic uuid.
Have you experienced an issue with this? If so, I can investigate.
It looks like .receiveBroadcastStream() will override the previous platform channel if it's called more than once. Good catch!
I'll use this opportunity to refactor some event channels to utilize the main method channel (#11).
Fix on the way.
That was quick! I can confirm it works for me now. Thanks :)
Most helpful comment
That was quick! I can confirm it works for me now. Thanks :)