Developing a BLE application on Android can be frustrating even under the best of conditions. SweetBlue does as much as it can to make your life easier, but sometimes further troubleshooting steps must be taken to establish a reliable connection...
- First and foremost please see Troubleshooting for Customer Service because most of the steps are applicable to developers as well.
- BleManager.reset() is a method that can help alleviate certain issues. You may want to attach this method to a button in your app in a "Settings" or "Help" screen.
- Make sure you're using the latest release of SweetBlue. New Android phones are always coming out and we're always finding new quirks that SweetBlue can cleanly work around under the hood. For end-users, make sure they're on the latest version of your app.
- When a phone and peripheral connect they negotiate several parameters including Connection Interval, Slave Latency, and Supervision Timeout. Read a bit more about these here: https://devzone.nordicsemi.com/question/60/what-is-connection-parameters/. Based on our experience, most companies configure their firmware with an iOS-first mindset, perhaps referencing https://developer.apple.com/hardwaredrivers/BluetoothDesignGuidelines.pdf for best practices. The end result is that their peripheral works great with iOS but when they start on their Android app they run into problems because Android usually requires more conservative connection parameters. Ideal parameters can also vary greatly from device to device, so in practice you may have to account for the lowest common denominator. Unfortunately the app has no control over these parameters - only the peripheral has any say. So if you have control over the firmware it is highly suggested to test for the best possible connection parameters and err on the side of conservative.
- As a continuation of the last point, often a device will request faster connection parameters before a firmware update or other "over-the-air" transfers of large chunks of data so that the transfer will take place as quickly as possible, then revert back to normal connection parameters when the transfer is done. The faster connection parameters (again usually tailored to iOS) can overload the Android BLE stack after a while and cause all sorts of issues, especially with multiple connections. So keep in mind that normal connection parameters and OTA connection parameters both have to be throttled back. Some good baselines for normal connection are 100-125ms Connection Interval, 3s Supervision Timeout, and 0 Slave Latency, while for OTA you can use 15-22.5ms Connection Interval, 720ms Supervision Timeout, and 0 Slave Latency. You will probably need to tweak them from there.
- Requiring Bonding/Pairing for encrypted characteristics can cause all kinds of problems. In general we don't recommend it at all. A LOT of work was put into SweetBlue to make bonding as seamless as possible, but it will still be a source of connection issues for your users. Like all software involving security and encryption, you have to weigh the security benefits vs. harming the user experience. See https://sweetblue.io/docs/Android-BLE-Issues#bonding-pairing-issues for a little more info.
- Google it. If your issue is very clear and reproducible there is likely a stackoverflow post that may help. At least it lets you know you're not alone.
- If all else fails, please get in touch by e-mailing us at SweetBlue@idevicesinc.com or by posting an issue in our forums.