Skip to content

[Bug]: First OnCharacteristicChanged not triggering subscription #1542

@Muehli-Industries

Description

@Muehli-Industries

Component/Nuget

BluetoothLE Client (Shiny.BluetoothLE)

What operating system(s) are effected?

  • iOS (13+ supported)
  • Mac Catalyst
  • Android (8+ supported)

Version(s) of Operation Systems

Android 14
iOS 18.2

Hosting Model

  • 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

  • I have supplied a reproducible sample that is NOT FROM THE SHINY SAMPLES!
  • 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)
  • I am Sponsor OR My GitHub account is 30+ days old
  • 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmore-info-neededMore information needs to be provided by the issue authorunverifiedThis issue has not been verified by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions