Flutter_blue: Can't receive notification from bluetooth device

Created on 14 May 2021  路  6Comments  路  Source: pauldemarco/flutter_blue

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.

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)

All 6 comments

Same problem. @pauldemarco

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

coduy96 picture coduy96  路  5Comments

pauldemarco picture pauldemarco  路  3Comments

a-v-ebrahimi picture a-v-ebrahimi  路  4Comments

ArcticSpaceFox picture ArcticSpaceFox  路  6Comments

M3sca picture M3sca  路  3Comments