![]() ![]() Moreover I have realised is that continous Bluetooth LE scanning can actually kill WIFI connection and make the WIFI adapter unable to re-connect to any WIFI network until BLE scan is ON. So turning WIFI OFF was no option for me. Is that the application I am developing needs both WIFI and continous Bluetooth LE scanning. I can confirm too, that turning WIFI OFF makes Bluetooth 4.0 more stable especially on Google Nexus (I have a Nexus 7). If you turn off Wifi, restarting Bluetooth fully recovers the BLE stack without the need to reboot the device in most cases.However, it also works fine on most devices with wifi turned on. If you turn off Wifi, the BLE stack gets much more stable.Restarting Bluetooth helps to fix problems with BLE in most cases.This work around is based on follwoing experiences. If that setting is enabled, my app turns off Wifi when the app is running (and turns it back on afterwards) I provide another setting "Turn off WiFi".A good point may also be if serviceDiscovery failes. If that setting is enabled, I restart Bluetooth at some points that indicate the begin of BLE stack becoming unstable. I provide the user a setting "Restart Bluetooth".Work around: I could "stabilize" my app doing that. As a last resort, turn off wifi to stabilize bluetooth.Ī pretty OK entry point for newcomers could be this video tutorial: Developing Bluetooth Smart Applications for Android The issue and work around described below is probably fixed now by OS updates I often see even on modern devices with Android 5, that Wifi interferes withs bluetooth and vice versa.If several commands get called short after another, the first one gets cancelled due to the synchronous nature of the gatt implementation. Gatt always can process one command at a time.Better not use #startLeScan(UUID serviceUuids, LeScanCallback callback) with the parameter to filter for certain service UUIDs because this is broken completely in Samsung Galaxy S3 with Android 4.3 and doesn't work for 128bit UUIDs in general.onLeScan(BluetoothDevice device, int rssi, byte scanRecord) in the same thread on Samsung Galaxy S3 with Android 4.3 (at least for build JSS15J.I9300XXUGMK6) Reason: BluetoothDevice#connectGatt(Context context, boolean autoConnect, BluetoothGattCallback callback) always fails, if called inside LeScanCallback(). Start a new thread inside onLeScan(.) and then connect.Work around: Always close gatt instances on disconnect and create a fresh instance of gatt on each connect. Some devices like Nexus 4 with Android 4.3 take 45+ seconds to connect using an existing gatt instance.(Perhaps some of those hints aren't necessary anymore due to Android OS updates.) I'm starting to wonder if it's an issue with this specific chip? I tested this on two other Nexus 4s with the same result: Connection to the SensorTag is successful the first or second time, but (according to the logs) fails to discover services thereafter, causing all sorts of crashes. I obtained a TI SensorTag (also based on the CC2541) to play around with and discovered that TI released an android app for the SensorTag yesterday. The device to which I am trying to connect is based on TI's CC2541 chip. It seems I was able to discover characteristics, but the first attempt to read returned a null value and disconnected soon thereafter.įailed Attempt 2 - An example where I am not even able to discover services/characteristics. I am able to connect, discover all services/characteristics, and read/write.įailed Attempt 1 - This is the next attempt after disconnecting from the successful connection above. Successful connection - First attempt after rebooting the phone and installing the app. ![]() Log dumps: For these logs I rooted my phone and upped the trace levels of related items in /etc/bluetooth/bt_nf Whenever a device is disconnected I make sure to call close() on the BluetoothGatt object and set it to null. Once this happens I have to uninstall the application, disable Bluetooth, and restart the phone before it will start working again. I can't find anything in the logs to indicate why this is happening. ![]() ![]() However, after disconnecting and re-connecting, I am often unable to either scan services/characteristics or unable to complete a read/write. After getting started with the official BLE APIs in Android 4.3, I have noticed that after I connect a device for the first time I am rarely able to successfully connect to / communicate with that device or any other device again.įollowing the guide here, I can successfully connect to a device, scan services and characteristics, and read/write/receive notifications without any issues. I am currently developing an application that will use Bluetooth Low Energy (testing on the Nexus 4). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |