shiny icon indicating copy to clipboard operation
shiny copied to clipboard

[Bug]: First OnCharacteristicChanged not triggering subscription

Open Muehli-Industries opened this issue 1 year ago • 2 comments

Component/Nuget

BluetoothLE Client (Shiny.BluetoothLE)

What operating system(s) are effected?

  • [X] iOS (13+ supported)
  • [ ] Mac Catalyst
  • [X] Android (8+ supported)

Version(s) of Operation Systems

Android 14 iOS 18.2

Hosting Model

  • [X] MAUI
  • [ ] Native/Classic Xamarin
  • [ ] Manual

Steps To Reproduce

`IDisposable notificationSubscription;

var c = await x.GetCharacteristicAsync("49535343-fe7d-4ae5-8fa9-9fafd205e455", "49535343-1e4d-4bd9-ba61-23c647249616"); if (c != null) { Debug.WriteLine($"Characteristic found"); if (c.CanNotify()) {
Debug.WriteLine($"Characteristic can notify");
Debug.WriteLine($"Subscribing characteristic");
this.notificationSubscription = x.NotifyCharacteristic(c).SubscribeAsync(async v => {
Debug.WriteLine("######################################################################"); } } }`

Expected Behavior

Shiny.BluetoothLE.IPeripheral: Information: [Native Method - OnCharacteristicChanged should always trigger the logic in the subscription.

Actual Behavior

Shiny.BluetoothLE.IPeripheral: Information: [Native Method - OnCharacteristicChanged sometimes is not firing the subscription for the first OnCharacteristicChanged.

Exception or Log output

[BluetoothAdapter] getBleEnabledArray(): ON [BluetoothAdapter] BLE support array set: [true, true, true, true, true, true, true] [BluetoothAdapter] getBleEnabledArray(): ON [BluetoothAdapter] semIsBleEnabled(): ON [BluetoothAdapter] getBleEnabledArray(): ON [BluetoothLeScanner] Start Scan with callback [BluetoothLeScanner] onScannerRegistered() - status=0 scannerId=5 mScannerId=0 [ViewRootImpl@d69eb92[MainActivity]] onDisplayChanged oldDisplayState=2 newDisplayState=2 [ProfileInstaller] Installing profile for de.companyname.app [BluetoothAdapter] getBleEnabledArray(): ON [BluetoothAdapter] getBleEnabledArray(): ON [BluetoothLeScanner] Stop Scan with callback [BluetoothAdapter] BluetoothAdapter() : de.companyname.app [0:] DEVICE disconnected [DOTNET] Disconnected [BluetoothAdapter] getBleEnabledArray(): ON [CompatibilityChangeReporter] Compat change id reported: 265103382; UID 10367; state: ENABLED [BluetoothGatt] connect() - device: XX:XX:XX:XX:FC:C9, auto: false [BluetoothGatt] registerApp() [BluetoothGatt] registerApp() - UUID=3793644c-b5c6-4adf-902e-e280aa9b8217 [BluetoothGatt] onClientRegistered() - status=0 clientIf=7 [BluetoothGatt] requestConnectionPriority() - params: 0 [DOTNET] Connecting [BluetoothAdapter] getBleEnabledArray(): ON [BluetoothGatt] onClientConnectionState() - status=0 clientIf=7 device=XX:XX:XX:XX:FC:C9 Thread started: #15 [0:] Searching Characteristics [app] Accessing hidden method Landroid/bluetooth/BluetoothGatt;->refresh()Z (unsupported, reflection, allowed) [BluetoothGatt] refresh() - device: XX:XX:XX:XX:FC:C9 [0:] Shiny.BluetoothLE.IPeripheral: Information: Clear Internal Cache Refresh Result: True [BluetoothGatt] discoverServices() - device: XX:XX:XX:XX:FC:C9 [DOTNET] Connected [0:] [BluetoothGatt] onConnectionUpdated() - Device=XX:XX:XX:XX:FC:C9 interval=6 latency=0 timeout=500 status=0 [BluetoothGatt] onConnectionUpdated() - Device=XX:XX:XX:XX:FC:C9 interval=36 latency=0 timeout=500 status=0 [BluetoothGatt] onConnectionUpdated() - Device=XX:XX:XX:XX:FC:C9 interval=6 latency=0 timeout=500 status=0 [BluetoothGatt] onSearchComplete() = Device=XX:XX:XX:XX:FC:C9 Status=0 [BluetoothGatt] onConnectionUpdated() - Device=XX:XX:XX:XX:FC:C9 interval=36 latency=0 timeout=500 status=0 [0:] Characteristic found [0:] Characteristic can notify [0:] Subscribing characteristic [0:] Shiny.BluetoothLE.IPeripheral: Information: Subscribing to Notification Characteristic 49535343-fe7d-4ae5-8fa9-9fafd205e455 / 49535343-1e4d-4bd9-ba61-23c647249616 [BluetoothGatt] setCharacteristicNotification() - uuid: 49535343-1e4d-4bd9-ba61-23c647249616 enable: true [0:] Shiny.BluetoothLE.IPeripheral: Information: Subscribed to Notification Characteristic 49535343-fe7d-4ae5-8fa9-9fafd205e455 / 49535343-1e4d-4bd9-ba61-23c647249616 [0:] Shiny.BluetoothLE.IPeripheral: Information: [Native Method - OnCharacteristicChanged] Service: 49535343-fe7d-4ae5-8fa9-9fafd205e455 - Characteristic: 49535343-1e4d-4bd9-ba61-23c647249616 - Status: <======= No Log output (##########) for this OnCharacteristicChanged Thread started: #16 [0:] Shiny.BluetoothLE.IPeripheral: Information: [Native Method - OnCharacteristicChanged] Service: 49535343-fe7d-4ae5-8fa9-9fafd205e455 - Characteristic: 49535343-1e4d-4bd9-ba61-23c647249616 - Status: [0:] ###################################################################### [0:] [Received] 0146F6","FID":"E4625 [0:] Shiny.BluetoothLE.IPeripheral: Information: [Native Method - OnCharacteristicChanged] Service: 49535343-fe7d-4ae5-8fa9-9fafd205e455 - Characteristic: 49535343-1e4d-4bd9-ba61-23c647249616 - Status: [0:] ###################################################################### [0:] [Received] 0224F435726","Ser":"

Code Sample

No response

Code of Conduct

  • [X] I have supplied a reproducible sample that is NOT FROM THE SHINY SAMPLES!
  • [X] I am a Sponsor OR I am using the LATEST stable/beta version from nuget (v3.0 stable - ALPHAS are not taking issues - Sponsors can still send v2 issues)
  • [X] I am Sponsor OR My GitHub account is 30+ days old
  • [X] I understand that if I am checking these boxes and I am not actually following what they are saying, I will be removed from this repository!

Muehli-Industries avatar Dec 14 '24 12:12 Muehli-Industries

I have not seen this issue before. Are you sending a notification immediately upon subscription? How do I repro this?

Have you tried WhenNotificationReceived & EnableNotification directly?

aritchie avatar Dec 16 '24 16:12 aritchie

Yes, the device i'm connecting with is sending data immediately upon subscription. I've not yet tried WhenNotificationReceived & EnableNotification.

Muehli-Industries avatar Dec 16 '24 16:12 Muehli-Industries