shinyorg / shiny

.NET Framework for Backgrounding & Device Hardware Services (iOS, Android, & Catalyst)
https://shinylib.net
MIT License
1.43k stars 227 forks source link

[Bug]: Connecting and disconnecting the connection does not work reliably #1433

Closed HausBJB closed 5 months ago

HausBJB commented 5 months ago

Component/Nuget

BluetoothLE Client (Shiny.BluetoothLE)

What operating system(s) are effected?

Version(s) of Operation Systems

Android 10 Works better Android 14 Does not work well

MAUI 8.0.10 Shiny 3.2.4

Hosting Model

Steps To Reproduce

  1. UseShiny()
  2. AddBluetoothLE()

Expected Behavior

I expect the following when I have searched for my devices and found my device and then connect to and disconnect from the device everything should work.

Unfortunately, it is not possible to connect immediately after disconnecting and, better said, it does not always work with Android 10 and with Android 14 it works even more unreliably I have of course looked at other apps, such as the "Serial Bluetooth Terminal" app, which allows me to connect to the same device and disconnect immediately and as often as I want. Most of the time there is a timeout error when connecting

Actual Behavior

The connection cannot be established and is disconnected again immediately After several attempts, a timeout error occurs while the connection is being established

Exception or Log output

[DOTNET] .........................................................................Connect 1 [BluetoothAdapter] getBleEnabledArray(): ON [BluetoothGatt] connect() - device: XX:XX:XX:XX:EA:BA, auto: true [BluetoothGatt] registerApp() [BluetoothGatt] registerApp() - UUID=112aa934-3a56-4b2f-8d3d-cfe216026b1a [BluetoothGatt] requestConnectionPriority() - params: 0 [BluetoothGatt] onClientRegistered() - status=0 clientIf=12 [BluetoothAdapter] getBleEnabledArray(): ON [BluetoothGatt] onClientConnectionState() - status=0 clientIf=12 device=XX:XX:XX:XX:EA:BA [DOTNET] .........................................................................Connect OK [BluetoothGatt] onConnectionUpdated() - Device=XX:XX:XX:XX:EA:BA interval=6 latency=0 timeout=500 status=0 [BluetoothGatt] close() [BluetoothGatt] unregisterApp() - mClientIf=12 [BluetoothGatt] onConnectionUpdated() - Device=XX:XX:XX:XX:EA:BA interval=24 latency=0 timeout=500 status=0 [DOTNET] .........................................................................Connect 2 [BluetoothAdapter] getBleEnabledArray(): ON [BluetoothGatt] connect() - device: XX:XX:XX:XX:EA:BA, auto: true [BluetoothGatt] registerApp() [BluetoothGatt] registerApp() - UUID=eae7f451-c318-4cb6-9bb6-d0f2867bbf61 [BluetoothGatt] requestConnectionPriority() - params: 0 [BluetoothGatt] onClientRegistered() - status=0 clientIf=12 [BluetoothAdapter] getBleEnabledArray(): ON [BluetoothGatt] onClientConnectionState() - status=0 clientIf=12 device=XX:XX:XX:XX:EA:BA [DOTNET] .........................................................................Connect 2 OK [BluetoothGatt] onConnectionUpdated() - Device=XX:XX:XX:XX:EA:BA interval=6 latency=0 timeout=500 status=0 [BluetoothGatt] onConnectionUpdated() - Device=XX:XX:XX:XX:EA:BA interval=24 latency=0 timeout=500 status=0 [BluetoothGatt] close() [BluetoothGatt] unregisterApp() - mClientIf=12 [ViewRootImpl@4455e40[MainActivity]] ViewPostIme pointer 0 [ViewRootImpl@4455e40[MainActivity]] ViewPostIme pointer 1 [DOTNET] .........................................................................Connect 1 [BluetoothAdapter] getBleEnabledArray(): ON [BluetoothGatt] connect() - device: XX:XX:XX:XX:EA:BA, auto: true [BluetoothGatt] registerApp() [BluetoothGatt] registerApp() - UUID=6d89fae2-87b2-47be-81f5-db22bddf99a1 [BluetoothGatt] requestConnectionPriority() - params: 0 [BluetoothGatt] onClientRegistered() - status=0 clientIf=12 [BluetoothAdapter] getBleEnabledArray(): ON [BluetoothGatt] close() [BluetoothGatt] unregisterApp() - mClientIf=12 [DOTNET] System.TimeoutException: The operation has timed out. [DOTNET] at MauiApp2.MainPage.StartTest(Object sender, EventArgs e) in D:\Temp\MauiApp2\MauiApp2\MainPage.xaml.cs:line 52

[DOTNET] .........................................................................Connect 1 [BluetoothAdapter] getBleEnabledArray(): ON [BluetoothGatt] connect() - device: XX:XX:XX:XX:EA:BA, auto: true [BluetoothGatt] registerApp() [BluetoothGatt] registerApp() - UUID=6e2e1cae-b2ba-415f-b4b6-01e2930866f8 [BluetoothGatt] requestConnectionPriority() - params: 0 [BluetoothGatt] onClientRegistered() - status=0 clientIf=13 [BluetoothAdapter] getBleEnabledArray(): ON [BluetoothGatt] onClientConnectionState() - status=0 clientIf=12 device=XX:XX:XX:XX:EA:BA [BluetoothGatt] onClientConnectionState() - status=0 clientIf=13 device=XX:XX:XX:XX:EA:BA Thread started: #17 [BluetoothGatt] close() [BluetoothGatt] unregisterApp() - mClientIf=13 [DOTNET] System.InvalidOperationException: GATT is not connected [DOTNET] at Shiny.BluetoothLE.Peripheral.AssertConnection() [DOTNET] at Shiny.BluetoothLE.Peripheral.<>c__DisplayClass74_0.b__0(IObserver1 ob) [DOTNET] at System.Reactive.Linq.QueryLanguage.CreateWithDisposableObservable1[[System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].SubscribeCore(IObserver`1 observer) System.InvalidOperationException: 'GATT is not connected'

[DOTNET] at System.Reactive.ObservableBase1[[System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Subscribe(IObserver1 observer) [DOTNET] --- End of stack trace from previous location --- [DOTNET] at MauiApp2.MainPage.StartTest(Object sender, EventArgs e) in D:\Temp\MauiApp2\MauiApp2\MainPage.xaml.cs:line 60 [BluetoothGatt] onClientConnectionState() - status=8 clientIf=12 device=XX:XX:XX:XX:EA:BA [DOTNET] System.InvalidOperationException: GATT is not connected [DOTNET] at Shiny.BluetoothLE.Peripheral.AssertConnection() [DOTNET] at Shiny.BluetoothLE.Peripheral.<>c__DisplayClass74_0.b__0(IObserver1 ob) [DOTNET] at System.Reactive.Linq.QueryLanguage.CreateWithDisposableObservable1[[System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].SubscribeCore(IObserver1 observer) [DOTNET] at System.Reactive.ObservableBase1[[System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Subscribe(IObserver`1 observer) [DOTNET] --- End of stack trace from previous location --- [DOTNET] at MauiApp2.MainPage.StartTest(Object sender, EventArgs e) in D:\Temp\MauiApp2\MauiApp2\MainPage.xaml.cs:line 60 [BluetoothGatt] onClientConnectionState() - status=0 clientIf=12 device=XX:XX:XX:XX:EA:BA System.InvalidOperationException: 'Loading...'

Thread finished: #16 Thread finished: #11 [BluetoothGatt] onConnectionUpdated() - Device=XX:XX:XX:XX:EA:BA interval=6 latency=0 timeout=500 status=0 [BluetoothGatt] onConnectionUpdated() - Device=XX:XX:XX:XX:EA:BA interval=24 latency=0 timeout=500 status=0 Thread finished: #8 Thread started: #18 Thread started: #19 [ViewRootImpl@4455e40[MainActivity]] onDisplayChanged oldDisplayState=2 newDisplayState=2 Der Thread 16 hat mit Code 0 (0x0) geendet. Der Thread 11 hat mit Code 0 (0x0) geendet. Der Thread 8 hat mit Code 0 (0x0) geendet. [mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: GATT is not connected [mono-rt] at Shiny.BluetoothLE.Peripheral.AssertConnection() [mono-rt] at Shiny.BluetoothLE.Peripheral.b82_0(CancellationToken ct) [mono-rt] at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception) [mono-rt] at System.Reactive.ExceptionHelpers.Throw(Exception exception) [mono-rt] at System.Reactive.Stubs.<>c.<.cctor>b__21(Exception ex) [mono-rt] at System.Reactive.AnonymousSafeObserver1[[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].OnError(Exception error) [mono-rt] at System.Reactive.Sink1[[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].ForwardOnError(Exception error) [mono-rt] at System.Reactive.Sink2[[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null],[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].OnError(Exception error) [mono-rt] at System.Reactive.Subjects.Subject1[[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].OnError(Exception error) [mono-rt] at System.Reactive.Sink1[[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].ForwardOnError(Exception error) [mono-rt] at System.Reactive.Sink2[[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null],[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].OnError(Exception error) [mono-rt] at System.Reactive.AutoDetachObserver1[[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].OnErrorCore(Exception exception) [mono-rt] at System.Reactive.ObserverBase1[[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].OnError(Exception error) [mono-rt] at System.Reactive.AnonymousSafeObserver1[[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].OnError(Exception error) [mono-rt] at System.Reactive.Sink1[[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].ForwardOnError(Exception error) [mono-rt] at System.Reactive.Linq.ObservableImpl.Switch`1.[[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].OnError(Exception error) [mono-rt] at System.Reactive.Sink1[[System.IObservable1[[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ForwardOnError(Exception error) [mono-rt] at System.Reactive.Sink2[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[System.IObservable1[[Shiny.BluetoothLE.BleCharacteristicResult, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnError(Exception error) [mono-rt] at System.Reactive.Sink1[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].ForwardOnError(Exception error) [mono-rt] at System.Reactive.Linq.ObservableImpl.Switch1.[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].OnError(Exception error) [mono-rt] at System.Reactive.Sink1[[System.IObservable1[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ForwardOnError(Exception error) [mono-rt] at System.Reactive.Sink2[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[System.IObservable1[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnError(Exception error) [mono-rt] at System.Reactive.Sink1[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].ForwardOnError(Exception error) [mono-rt] at System.Reactive.Linq.ObservableImpl.Switch1..InnerObserver[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].OnError(Exception error) [mono-rt] at System.Reactive.Sink1[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].ForwardOnError(Exception error) [mono-rt] at System.Reactive.Sink2[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].OnError(Exception error) [mono-rt] at System.Reactive.Sink1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].ForwardOnError(Exception error) [mono-rt] at System.Reactive.Sink2[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].OnError(Exception error) [mono-rt] at System.Reactive.Sink1[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ForwardOnError(Exception error) [mono-rt] at System.Reactive.Sink2[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnError(Exception error) [mono-rt] at System.Reactive.AutoDetachObserver1[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnErrorCore(Exception exception) [mono-rt] at System.Reactive.ObserverBase1[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnError(Exception error) [mono-rt] at System.Reactive.SafeObserver1.WrappingSafeObserver[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnError(Exception error) [mono-rt] at System.Reactive.Sink1[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ForwardOnError(Exception error) [mono-rt] at System.Reactive.Linq.ObservableImpl.Throw1._.<>c[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].b20( this) [mono-rt] at System.Reactive.Concurrency.Scheduler.<>c751[[System.Reactive.Linq.ObservableImpl.Throw1._[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Reactive, Version=6.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263]].<ScheduleAction>b__75_0(IScheduler _, ValueTuple2 tuple) [mono-rt] at System.Reactive.Concurrency.ImmediateScheduler.Schedule[ValueTuple2](ValueTuple2 state, Func3 action) [mono-rt] at System.Reactive.Concurrency.Scheduler.ScheduleAction[_](IScheduler scheduler, _ state, Action1 action) [mono-rt] at System.Reactive.Linq.ObservableImpl.Throw1._[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Run(IScheduler scheduler) [mono-rt] at System.Reactive.Linq.ObservableImpl.Throw1[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Run( sink) [mono-rt] at System.Reactive.Producer2[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Reactive.Linq.ObservableImpl.Throw`1.[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Reactive, Version=6.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263]].SubscribeRaw(IObserver1 observer, Boolean enableSafeguard) [mono-rt] at System.Reactive.Producer2[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Reactive.Linq.ObservableImpl.Throw1._[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Reactive, Version=6.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263]].Subscribe(IObserver1 observer) [mono-rt] at System.Reactive.Linq.QueryLanguage.StartAsyncObservable1[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].SubscribeCore(IObserver1 observer) [mono-rt] at System.Reactive.ObservableBase1[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Subscribe(IObserver1 observer) [mono-rt] at System.ObservableExtensions.SubscribeSafe[IReadOnlyList1](IObservable1 source, IObserver1 observer) [mono-rt] at System.Reactive.Sink2[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Run(IObservable1 source) [mono-rt] at System.Reactive.Linq.ObservableImpl.Defer1._[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Run() [mono-rt] at System.Reactive.Linq.ObservableImpl.Defer1[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Run( sink) [mono-rt] at System.Reactive.Producer2[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Reactive.Linq.ObservableImpl.Defer`1.[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Reactive, Version=6.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263]].SubscribeRaw(IObserver1 observer, Boolean enableSafeguard) [mono-rt] at System.ObservableExtensions.SubscribeSafe[IReadOnlyList1](IObservable1 source, IObserver1 observer) [mono-rt] at System.Reactive.Sink2[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].Run(IObservable1 source) [mono-rt] at System.Reactive.Linq.ObservableImpl.Select2.Selector[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].Run( sink) [mono-rt] at System.Reactive.Producer2[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[System.Reactive.Linq.ObservableImpl.Select2.Selector.[[System.Collections.Generic.IReadOnlyList1[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Reactive, Version=6.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263]].SubscribeRaw(IObserver1 observer, Boolean enableSafeguard) [mono-rt] at System.ObservableExtensions.SubscribeSafe[BluetoothGattService](IObservable1 source, IObserver1 observer) [mono-rt] at System.Reactive.Sink2[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].Run(IObservable1 source) [mono-rt] at System.Reactive.Linq.ObservableImpl.Select2.Selector[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].Run(_ sink) [mono-rt] at System.Reactive.Producer2.<>c[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[System.Reactive.Linq.ObservableImpl.Select`2.Selector._[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Reactive, Version=6.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263]].b1_0(ValueTuple2 tuple) [mono-rt] at System.Reactive.Concurrency.Scheduler.<>c__751[[System.ValueTuple2[[System.Reactive.Producer2[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[System.Reactive.Linq.ObservableImpl.Select2.Selector._[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Reactive, Version=6.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263]], System.Reactive, Version=6.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263],[System.Reactive.Linq.ObservableImpl.Select2.Selector._[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Reactive, Version=6.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].b750(IScheduler , ValueTuple2 tuple) [mono-rt] at System.Reactive.Concurrency.CurrentThreadScheduler.Schedule[ValueTuple2](ValueTuple2 state, TimeSpan dueTime, Func3 action) [mono-rt] at System.Reactive.Concurrency.LocalScheduler.Schedule[ValueTuple2](ValueTuple2 state, Func3 action) [mono-rt] at System.Reactive.Concurrency.Scheduler.ScheduleAction[ValueTuple2](IScheduler scheduler, ValueTuple2 state, Action1 action) [mono-rt] at System.Reactive.Producer2[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[System.Reactive.Linq.ObservableImpl.Select2.Selector.[[Android.Bluetooth.BluetoothGattService, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Reactive, Version=6.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263]].SubscribeRaw(IObserver1 observer, Boolean enableSafeguard) [mono-rt] at System.ObservableExtensions.SubscribeSafe[BluetoothGattCharacteristic](IObservable1 source, IObserver1 observer) [mono-rt] at System.Reactive.Linq.ObservableImpl.Switch1.[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].OnNext(IObservable1 value) [mono-rt] at System.Reactive.Sink1[[System.IObservable1[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ForwardOnNext(IObservable1 value) [mono-rt] at System.Reactive.Linq.ObservableImpl.Select2.Selector._[[Shiny.BluetoothLE.IPeripheral, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null],[System.IObservable1[[Android.Bluetooth.BluetoothGattCharacteristic, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnNext(IPeripheral value) [mono-rt] at System.Reactive.Sink1[[Shiny.BluetoothLE.IPeripheral, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].ForwardOnNext(IPeripheral value) [mono-rt] at System.Reactive.Linq.ObservableImpl.Select2.Selector.[[Shiny.BluetoothLE.ConnectionState, Shiny.BluetoothLE.Common, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null],[Shiny.BluetoothLE.IPeripheral, Shiny.BluetoothLE, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].OnNext(ConnectionState value) [mono-rt] at System.Reactive.Sink1[[Shiny.BluetoothLE.ConnectionState, Shiny.BluetoothLE.Common, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].ForwardOnNext(ConnectionState value) [mono-rt] at System.Reactive.Linq.ObservableImpl.Where1.Predicate.[[Shiny.BluetoothLE.ConnectionState, Shiny.BluetoothLE.Common, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].OnNext(ConnectionState value) [mono-rt] at System.Reactive.Sink1[[Shiny.BluetoothLE.ConnectionState, Shiny.BluetoothLE.Common, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].ForwardOnNext(ConnectionState value) [mono-rt] at System.Reactive.IdentitySink1[[Shiny.BluetoothLE.ConnectionState, Shiny.BluetoothLE.Common, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].OnNext(ConnectionState value) [mono-rt] at System.Reactive.Subjects.Subject`1[[Shiny.BluetoothLE.ConnectionState, Shiny.BluetoothLE.Common, Version=3.3.0.0, Culture=neutral, PublicKeyToken=null]].OnNext(ConnectionState value) [mono-rt] at Shiny.BluetoothLE.Peripheral.OnConnectionStateChange(BluetoothGatt gatt, GattStatus status, ProfileState newState) [mono-rt] at Android.Bluetooth.BluetoothGattCallback.n_OnConnectionStateChange_Landroid_bluetooth_BluetoothGatt_II(IntPtr jnienv, IntPtr nativethis, IntPtr native_gatt, Int32 native_status, Int32 native_newState) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Bluetooth.BluetoothGattCallback.cs:line 289 [mono-rt] at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLII_V(_JniMarshal_PPLII_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, Int32 p1, Int32 p2) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 301

Code Sample

https://github.com/HausBJB/MauiApp2/archive/refs/heads/master.zip

Code of Conduct

aritchie commented 5 months ago

Set a try catch on the connect/disconnect which you'll always want to do anyhow. If your rapidly connecting/disconnecting, await the disconnection event. I don't have a DisconnectAsync at the moment because this isn't a use-case that I have ever seen really used.

HausBJB commented 5 months ago

Ok thanks for the reply, I will try that with the disconnect event. I had previously built a DisconnectAsync that always queried the disconnected status in the while loop, but even then I had problems disconnecting and reconnecting. One use case would be to use multiple devices that you want to switch back and forth or should you then not disconnect the existing connection?

Ok anyway, thanks for the reply and the ticket can be closed, I will try to do it with the disconnect event.

Thanks for the answer

aritchie commented 5 months ago

One use case would be to use multiple devices that you want to switch back and forth or should you then not disconnect the existing connection?

It depends on your business need. If you're rapidly connecting and disconnecting, why not just stay connected? All I can say for this issue is that you have to wait for the disconnect to complete before you can send another connection request