Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification stream of characteristic doesnt work #102

Open
vovagorodok opened this issue Oct 6, 2024 · 6 comments
Open

Notification stream of characteristic doesnt work #102

vovagorodok opened this issue Oct 6, 2024 · 6 comments

Comments

@vovagorodok
Copy link

vovagorodok commented Oct 6, 2024

characteristicRx.readValue() and characteristicTx.writeValue(data, type: BlueZGattCharacteristicWriteType.command); works correctly on Central. Peripheral (Arduino) device receives write without response and notifies on characteristicRx, but nothing happens on propertiesChanged stream (waiting 5 seconds).

await characteristicRx.startNotify();
_subscription = characteristicRx.propertiesChanged
    .where((properties) => properties.contains('Value'))
    .listen((properties) {
  print("Received data: ${characteristic.value}");
});
print("Is notifying: ${characteristic.notifying}");

Only print Is notifying: false is visible.
Not sure if I'm doing something wrong. Can't find example of characteristic notification receiving.
Code that I'm working on: https://github.com/vovagorodok/ble_backends/blob/main/packages/bluez_backend/lib/bluez_characteristic.dart

@jefflongo
Copy link

Have you tried making sure on the Arduino side the notification is getting sent? My project uses the exact same method for listening for notifications (well I subscribe first then call startNotify) and it works just fine.

@vovagorodok
Copy link
Author

vovagorodok commented Oct 9, 2024

Have you tried making sure on the Arduino side the notification is getting sent?

Yes, checking on debug/serial logs. I am working on BLE libraries wrapper in order to easily swap between libraries in my app. Wrapper works correctly with flutter_reactive_ble, flutter_web_bluetooth, win_ble...

My project uses the exact same method for listening for notifications (well I subscribe first then call startNotify) and it works just fine.

Changing order of subscribe and startNotify doesn't help. I'm on latest Fedora. What distro do you have?

@jefflongo
Copy link

I'm using Ubuntu 24.04. Could be worth monitoring btmon and check the logs there.

@vovagorodok
Copy link
Author

Captured only moment where we write without response Data[5]: 10804f0900 and waiting for notification Data[9]: 00ef00000000000000:

$ sudo btmon
Bluetooth monitor ver 5.78
btmon[89032]: = Note: Linux version 6.10.12-200.fc40.x86_64 (x86_64)                                                                                                                                                                 0.318844
btmon[89032]: = Note: Bluetooth subsystem version 2.22                                                                                                                                                                               0.318847
= New Index: F8:AC:65:DE:85:5E (Primary,USB,hci0)                                                                                                                                                                             [hci0] 0.318848
= Open Index: F8:AC:65:DE:85:5E                                                                                                                                                                                               [hci0] 0.318848
= Index Info: F8:AC:65:DE:85:5E (Intel Corp.)                                                                                                                                                                                 [hci0] 0.318849
bluetoothd[2254]: @ MGMT Open: bluetoothd (privileged) version 1.22                                                                                                                                                         {0x0001} 0.318850
bluetoothd[2254]: < ACL Data TX: Handle 3585 flags 0x00 dlen 9                                                                                                                                                            #1 [hci0] 54.414528
      ATT: Write Request (0x12) len 4
        Handle: 0x000f
          Data[2]: 0100
> HCI Event: Number of Completed Packets (0x13) plen 5                                                                                                                                                                    #2 [hci0] 54.429210
        Num handles: 1
        Handle: 3585
        Count: 1
> ACL Data RX: Handle 3585 flags 0x02 dlen 5                                                                                                                                                                              #3 [hci0] 54.475752
      ATT: Write Response (0x13) len 0
bluetoothd[2254]: < ACL Data TX: Handle 3585 flags 0x00 dlen 12                                                                                                                                                           #4 [hci0] 54.482542
      ATT: Write Command (0x52) len 7
        Handle: 0x000c
          Data[5]: 10804f0900
> HCI Event: Number of Completed Packets (0x13) plen 5                                                                                                                                                                    #5 [hci0] 54.519211
        Num handles: 1
        Handle: 3585
        Count: 1
> ACL Data RX: Handle 3585 flags 0x02 dlen 16                                                                                                                                                                             #6 [hci0] 54.565747
      ATT: Handle Value Notification (0x1b) len 11
        Handle: 0x000e
          Data[9]: 00ef00000000000000

Looks that we receive expected data from peripheral, but buez library doesn't notify us, some issue on systemd level?

@vovagorodok
Copy link
Author

Also checked the same functionality on python bleak library: https://github.com/vovagorodok/ArduinoBleOTA/blob/main/tools/uploader.py
And looks that it works correctly, we receive notification and start uploading

@vovagorodok
Copy link
Author

vovagorodok commented Oct 9, 2024

@dkwach checked identical functionality with bluez.dart on his Ubuntu 24.04. And it works correctly and Data[9]: 00ef00000000000000 was notified. Looks that it's some issue with Fedora 40 + bluez.dart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants