Good morning,
I have activated notification on a characteristic, but I can't receive any notification.
I don't know if it's a problem of implementation of if I am missing something, but maybe you can help me.
await mTxCharacteristic.setNotifyValue(true);
mTxCharacteristic.value.listen((value) {
print("$value");
});
I should receive notifications on mTxCharacteristic when I write commands to mRxCharacteristic with
...
await mRxCharacteristic.write(command.toList());
...
but print("$value") is never called.
Thank you in advance if you can help me.
Same problem. @pauldemarco
@maddionatoplus check https://github.com/pauldemarco/flutter_blue/issues/841 and https://github.com/pauldemarco/flutter_blue/issues/840
Thank you for your answer.
I already call setNotifyValue(false) before:
await mTxCharacteristic.setNotifyValue(false);
await desc.write([0x01, 0x00]);
await mTxCharacteristic.setNotifyValue(true);
mTxCharacteristic.value.listen((value) {
print("$value");
});
and I write a descriptor to [0x01, 0x00] to set the characteristic to notification (otherwise [0x02, 0x00] is for indication).
I didn't try to wait 0.5 in between. Isn't await enough?
Another question, in this way I should receive notification inside the listener in any moment after that time, correct?
try this:
await mTxCharacteristic.setNotifyValue(false);
await mTxCharacteristic.setNotifyValue(true);
mTxCharacteristic.value.listen((value) {
print("$value");
});
await desc.write([0x01, 0x00]);
i think you need to set the listener first and afterwards call the write function.
ok, I'm going to try. Just to be more accurate, the desc.write() is not the call that should give me the notifications, it's just to specify to the device that it should be set to notification (instead of indication).
I call the write on the characteristic (that should generate notification) after in the code (when user does a specificy interaction)
ok thanks guys, it worked in this way:
`
await mTxCharacteristic.setNotifyValue(false);
await Future.delayed(const Duration(milliseconds: 250)); // don't know if necessary
await mTxCharacteristic.setNotifyValue(true);
mTxCharacteristic.value.listen((value) {
print("$value");
});
await desc.write([0x02, 0x00]);`
it was [0x02, 0x00] because it was indication and not notification
Most helpful comment
ok, I'm going to try. Just to be more accurate, the desc.write() is not the call that should give me the notifications, it's just to specify to the device that it should be set to notification (instead of indication).
I call the write on the characteristic (that should generate notification) after in the code (when user does a specificy interaction)