Proper way to handle BLE Error Codes - android

Here is the list of error which i got while developing BLE App for A&D UA-651BLE model
onClientConnectionState() - status=8 clientIf=5 device=D0:5F:B8:03:79:70
onClientConnectionState() - status=22 clientIf=5 device=5C:31:3E:5E:E2:36
onClientConnectionState() - status=19 clientIf=5 device=5C:31:3E:5E:E2:36
As of now I'm handling this with gatt.disconnect(); ,
Description of above error codes :
22 is 0x16 which means connection terminated by local host.
8 is 0x8 which means connection timeout.
19 is 0x13 which means connection terminate by peer user.
How to handle this in different way?
1.Is there any way to handle this issue other than disconnecting BluetoothGatt? (Just curious to know)
2.Shall I show popup to user that your values are stored in BP device,On next successful connection vital device will push your values automatically?
P.S: If I see from developer's perspective,I know that this is BLE Stack exception,By if i see from user's perspective,they will think something wrong in android app,that is why it is not Showing my BP reading in android Screen.

Related

flutter blue example can't connect to gatt server

I am trying to create an application (on flutter/android studio) that can connect to a Ble server and read his characteristics. I used the flutter_blue_example : https://github.com/pauldemarco/flutter_blue/tree/master/example .
The scan goes fine, but when I try to connect to the BLE device it does'nt work and I get the following log on android studio :
D/BluetoothGatt( 8205): onClientConnectionState() - status=133 clientIf=8
device=00:1A:7D:DA:71:13
D/FlutterBluePlugin( 8205): onConnectionStateChange:
D/BluetoothGatt( 8205): close()
D/BluetoothGatt( 8205): unregisterApp() - mClientIf=8
I used the following example to create my Ble server : https://github.com/Jumperr-labs/python-gatt-server
The problem could come from the server but as it works good with an app like Ble scanner available on the playstore, I think the problem is more likely to come from the app based on flutter.
I finally found that I had to pair with the device in the bluetooth parameters before launching my app. BTW there are still issues with the refresh of the discovered services, but I am working on it.

BluetoothGattCharacteristic limit causing issues?

In my app I have tried everything to connec my BLE device and receive calls to onCharacteristicChanged. I have had success with initial connection where my console reads like this:
BluetoothGatt: onConnectionUpdated() - Device=B4:E6:2D:B3:D0:DB interval=6 latency=0 timeout=500 status=0
BluetoothGatt: setCharacteristicNotification() - uuid: 0a990c1f-0000-441c-8f7d-f775b6ff9400 enable: true
BluetoothGatt: setCharacteristicNotification() - uuid: f7c21d1c-0000-4b9b-ab7e-e1d8e7a51724 enable: true
Although I have no calls to onCharacteristicChanged?
I am not sure this is the proper way to check but I have used nRF Connect app to test if there is any activity between the BLE device and the Android phone. Using that app, it recoded no activity after connecting to the device. Just to be sure, I tested other BLE devices and saw the expected activity.
The BLE device has 8 characteristics that I read/get notified from, and another 8 that I write to (16 total). I have read that Android may only support 15, I could be wrong on how this works.
Does any of this seem like an issue? I can post code too.

Programmatically detecting changes to BLE connection parameters

I want some way to read the connection parameters programatically in Android BLE.
Android's BluetoothGatt class, as of API 21, provides these three modes to set up connection parameters.
CONNECTION_PRIORITY_BALANCED
Connection paramter update - Use the connection paramters recommended by the Bluetooth SIG.
CONNECTION_PRIORITY_HIGH
Connection paramter update - Request a high priority, low latency connection.
CONNECTION_PRIORITY_LOW_POWER
Connection paramter update - Request low power, reduced data rate connection parameters.
These have been discussed in detail here, and here.
Since none of these give me the connection interval that I want, so tried performing a connection update from the side of my peripheral. Luckily, that seems to work. After I send the connection update I can see in Logcat:
D/BluetoothGattServer: onConnectionUpdated() - Device=XX:XX:XX:XX:XX:XX interval=1596 latency=0 timeout=512 status=0
D/BluetoothGatt: onConnectionUpdated() - Device=XX:XX:XX:XX:XX:XX interval=1596 latency=0 timeout=512 status=0
I don't care what interval the Android devices chooses, so long as it is between 1000ms and 2000ms. While it is easy to see this change occurring in the logs, I have yet to find a way to read the interval value programatically. I would like to make sure this update occurred so that I am not wasting battery life on my peripheral.
No. But if you can detect the update from the peripheral side then you can send a notification to the central with the new parameters.

BluetoothGatt: onClientConnParamsChanged()

I am developing an Android App that communicates with a BLE Peripheral. I am able to enable the notifications and receive data from the BLE Peripheral. However, a few seconds later, I receive the following message on my Android Terminal in Android Studio and the Notifications stop.
I noticed that Android phone is still connected to the BLE Peripheral as Status = 0, but after the BLE Connection Interval Change = 156, the Notifications stop.
Has anyone encountered a similar problem? I am using the BluetoothLEGatt example from Android Studio.
Thanks
Hani Abidi
D/BluetoothGatt: onClientConnParamsChanged() - Device=80:EA:CA:00:A8:77 interval=156 status=0enter code here
So I ran into this issue as well and although I don't 100% know the exact cause, I can at least relay how I "fixed" the problem and my experiences.
So I'm using a Samsung Galaxy Note 4 running 6.0.1 and using RxAndroidBle to ease the pain of having to deal with BLE on Android. My application connects to a PSoC4 BLE microprocessor and immediately does a back and forth data transfer with said microprocessor. What I was seeing was similar to the OP: more often than not the back and forth transmission would just stop dead in its tracks with the following messages:
03-15 16:06:39.989 27793-28784/application D/BluetoothGatt: onClientConnParamsChanged() - Device=00:A0:50:65:24:91 interval=6 status=0
03-15 16:06:40.289 6292-6754/? D/BtGatt.GattService: onClientConnParamsChanged() - clientIf=7 address=00:A0:50:65:24:91, interval=39status=0
03-15 16:06:40.289 27793-28561/application D/BluetoothGatt: onClientConnParamsChanged() - Device=00:A0:50:65:24:91 interval=39 status=0
03-15 16:06:54.989 6292-6754/? D/BtGatt.GattService: onClientConnParamsChanged() - clientIf=7 address=00:A0:50:65:24:91, interval=6status=0
03-15 16:06:54.989 27793-27823/application D/BluetoothGatt: onClientConnParamsChanged() - Device=00:A0:50:65:24:91 interval=6 status=0
03-15 16:06:55.259 6292-6754/? D/BtGatt.GattService: onClientConnParamsChanged() - clientIf=7 address=00:A0:50:65:24:91, interval=39status=0
03-15 16:06:55.259 27793-28784/application D/BluetoothGatt: onClientConnParamsChanged() - Device=00:A0:50:65:24:91 interval=39 status=0
It appeared to me at first that for some reason the phone was still negotiating the connection interval in the middle of the data transfer and, for some reason, would just completely get screwed up as a result.
Maybe this is what is happening, maybe it isn't, but what I found was the root cause of this was that I am (apparently) connecting and interfacing with my microprocessor over BLE before the BLE device scanner is completely done shutting down.
When the user taps on the table view cell to connect to the device, I was originally calling to stop subscribing to the RxAndroidBle observable that is scanning for devices, which should end the BLE scanning and then immediately launched into showing a new Activity for communicating with the PSoC4 which in turn immediately connects and starts interfacing with the microprocessor:
scanSubscription.unsubscribe();
Intent myIntent = new Intent(MainActivity.this, ConnectedActivity.class);
myIntent.putExtra("address", testdevice.getAddress());
myIntent.putExtra("name", testdevice.getName());
MainActivity.this.startActivityForResult(myIntent, CONNECTED_ACTIVITY);
It appears, however, that simply unsubscribing from the scan subscription does not immediately end the BLE scanning so my current strategy is to wait 500 ms before starting any communications with the other device. This is obviously not ideal - ideally you'd have a method callback when scanning actually was ceased, but I haven't figured out how to do that just yet.
Hopefully this helps someone.
Connection parameter update is unrelated to notification subscription status. Are you saying your onCharacteristicChanged are not being called although you send notifications from the peripheral? You should check your code again. If you think you've done everything correct you should check android's hci snoop log or use a BLE sniffer to see what really happens.

Android BluetoothGatt status code 128 BLE connection

I'm trying to connect a BLE Device (Sigma chest strap) to my Sony Smartwatch 3 and the writeDescriptor() method fails to enable Notifications on the Device. The onDescriptorWrite() method displays the status code "128" which apparently stands for "GATT_NO_RESOURCES". Does anyone know what this error means or how to fix it?
Another BLE Device (Alpha Mio 2) works without any problems. descriptor is written and data received via onCharacteristicChanged().
Descriptor UUID: 00002902-0000-1000-8000-00805f9b34fb
Service UUID: 0000180d-0000-1000-8000-00805f9b34fb

Categories

Resources