I'm trying to write an app to connect to a BLE device (using a Cypress PSoC pioneer board) my team is working on. Right now I'm hung up on getting the app to detect any devices at all.
I'm testing the app on an HTC Desire 510, and the device I'm trying to detect is the PSoC board running Cypress's proximity sensor example.
After lots of frustration, I tried running the entire API-21 BluetoothLEGatt sample on my device and it detects (and can connect to) the board no problem.
I then tried copying the entire DeviceScanActivity into my project making only the following modifications:
I turned the toast messages into logcat messages
I removed the content of onListItemClick since that references an Activity I don't have
I changed a couple of labels to String values already in my project
My AndroidManifest has both BLUETOOTH and BLUETOOTH_ADMIN and is setup to launch the activity directly.
When I run it in my project the phone doesn't detect any devices, and I get the following logcat output when scanning:
04-13 17:51:25.350 3892-3892/com.fredwilby.chipper D/BluetoothAdapter﹕ startLeScan(): null
04-13 17:51:25.350 3892-3903/com.fredwilby.chipper D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
04-13 17:51:27.350 3892-3892/com.fredwilby.chipper I/Choreographer﹕ Skipped 120 frames! The application may be doing too much work on its main thread.
04-13 17:51:31.940 3892-3892/com.fredwilby.chipper D/BluetoothAdapter﹕ stopLeScan()
compared to the output when I scan from the Sample project:
04-13 18:05:36.750 6887-6887/com.example.android.bluetoothlegatt D/BluetoothAdapter﹕ startLeScan(): null
04-13 18:05:36.750 6887-6899/com.example.android.bluetoothlegatt D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
04-13 18:05:37.120 6887-6898/com.example.android.bluetoothlegatt D/BluetoothAdapter﹕ onScanResult() - Device=00:A0:50:00:00:69 RSSI=-59
04-13 18:05:37.120 6887-6898/com.example.android.bluetoothlegatt D/BluetoothDevice﹕ getService() entry
04-13 18:05:38.080 6887-6887/com.example.android.bluetoothlegatt D/BluetoothAdapter﹕ stopLeScan()
I don't get the message about skipped frames everytime I scan from my app, but it's quite frequent and was even more so when I was trying to make code I wrote work.
I've tried rebooting the device to no avail, and I really don't know what else I can try at this point. Does anyone have any insight into how I can get this to work?
I'm happy to post any other information that would be helpful. I've omitted the code here because, as I mentioned above, it's identical to the sample except for very minor cosmetic tweaks (nothing anywhere near the scanning code).
Well, I managed to fix it by removing <uses-sdk android:minSdkVersion="18" android:targetSdkVersion="21" /> from my AndroidManifest. Of course this is kind of an infuriating fix and I'd appreciate if anyone had any insight into why this happens.
Related
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.
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.
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.
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.
I have a Android Service which scans for Bluetooth Low Energy devices. This works but if the app is killed the scan dont work. The service is running but I see in the logcat that the binder for bluetooth is dead.
D/BtGatt.GattService(3088): Binder is dead - unregistering client (5)!
D/BtGatt.GattService(3088): stopScan() - queue=1
D/BtGatt.GattService(3088): stopScan() - queue empty; stopping scan
D/BtGatt.btif(3088): btif_gattc_scan
D/BtGatt.btif(3088): btgattc_handle_event: Event 1003
D/BtGatt.GattService(3088): unregisterClient() - clientIf=5
D/BtGatt.btif(3088): btif_gattc_unregister_app
D/BtGatt.btif(3088): btgattc_handle_event: Event 1001
D/BtGatt.btif(3088): btif_gattc_upstreams_evt: Event 1
How can i scan for bluetooth devices with a service? Thank you
Unlike previous versions, in 4.4 swiping app out of recent tasks permanently kills app along with its service (like force-stop) even though it's running background services. Here you can find a "quick and dirty workaround":
In android 4.4, swiping app out of recent tasks permanently kills application with its service . Any idea why?