0

I am getting a GattCallback error: 133 when writing data to the device.It happens, the app is in the background mode or killed state.

            using (IDevice _device = await adapter.ConnectToKnownDeviceAsync(deviceID, new ConnectParameters(false, false), cancellationToken: _cancellationTokenSource.Token))
            {
                _cancellationTokenSource = new CancellationTokenSource();
                _cancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(30));

                //    TestingValue("49");

                using (IService _service = await _device.GetServiceAsync(Guid.Parse("00008592-0000-1000-8000-00805f7b45fg"), _cancellationTokenSource.Token))
                {
                    if (_service != null)
                    {
                        ICharacteristic _characteristic =
                            await _service.GetCharacteristicAsync(Guid.Parse("00002a06-0000-1000-8000-00805f7b45fg"));

                        if (_characteristic != null)
                        {
                            _characteristic.WriteType = CharacteristicWriteType.WithoutResponse;

                            _cancellationTokenSource = new CancellationTokenSource();
                            _cancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(30));

                            await _characteristic.WriteAsync(data, _cancellationTokenSource.Token);
                            await Task.Delay(3000);
                        }
                    }
                }

I want to make sound in my ble device when choosing an option or when a notification comes in the app.It works perfectly in some devices.But in some devices I got a 133 Gatt error when the app is in the background mode and killed state after that it doesn't work in all the state.

Please help me...

John
  • 35
  • 7

1 Answers1

2

I've recently run into this problem. During my research I found this issue on GitHub: https://github.com/xabre/xamarin-bluetooth-le/issues/276 Initializing ConnectParameters with autoConnect set to true seems to have hit the nail on the head. I warmly encourage you to read this topic.

new ConnectParameters(true, false)

I'm going to further investigate it, especially that matter with the adepter calls being not thread-safe.

Additionally, in the documentation: https://github.com/xabre/xamarin-bluetooth-le there are some interesting informations ('Caution! Important remarks / API limitations' nad 'Best Practise' sections), I'd like to check.