-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Very frequent connect/disconnect issue #185
Comments
hmmm interesting. Sounds like something isn't being cleaned up properly. What do you see in the logs when it stops working? please share logs |
First, thanks for your asnwer!
onConnectedPeripheral: D0:74:F5:B1:18:59 The below is the last working connect/disconnect cycle on Android side:
After that, the BLE has overfloated and the log has no other entries with BLE TAG. ` 23:32:28.807 -> Conn: Galaxy A71, CC=190 23:32:34.177 -> Conn: Galaxy A71, CC=191 23:32:39.601 -> Conn: Galaxy A71, CC=192 23:32:44.993 -> Conn: Galaxy A71, CC=193 23:32:46.676 -> Conn: Galaxy A71, CC=194 For comparison on the BLE device side, when autoconnecting from the NRF Connect app the counter was 17217 when I manually disconnected it (=no BLE overfloating): 23:14:37.085 -> Conn: Galaxy A71, CC=17213 23:14:38.254 -> Conn: Galaxy A71, CC=17214 23:14:39.472 -> Conn: Galaxy A71, CC=17215 23:14:40.688 -> Conn: Galaxy A71, CC=17216 23:14:41.890 -> Conn: Galaxy A71, CC=17217 |
Ok that doesn't say much that would lead us to a solution. You mentioned that you have an app with which you can reproduce the issue? Can you share that? Then I'll try to reproduce the issue myself. What I see in the logs is that you do more than just connecting. You change MTU, connection settings, Phy and turn on notifications...that might give a clue. Do you also do that with the nRF app? Another thing worth trying is to wait 5 seconds before you issue the autoConnect. I have noticed that the Android stack sometimes needs some time to process the disconnect.... |
My android app is supposed to do much more than just connecting to one sensor with no data transfer. Initially, I had 8 sensors in an array of peripherals with full data transfer (max MTU, data receiving in notifications on a per sensor basis, etc.) On having noticed the problem, I started removing functionality from the app, until I came to the one sensor connect/disconnect problem without any data transfer. That is why parts of the initial code are still there (MTU, notifications, connection params were requested in onServicesDiscovered and in the BLE device, as well). As for issuing autoconnect with a delay, NRF Connect handles it immediately without delay, so it must work anyway. I have further investigated into this issue on the BLE device side. I switched on counting all disconnect reasons (current and previous ones). 20:34:29.605 -> Conn: Galaxy A71, CC=2769 As you can see, there are only two reasons of disconnect. 95% of all disconnects (2639/2772=0.95) are 0x16 = Local Host Terminated Connection and 5% are 0x22 = LMP_RESPONSE_TIMEOUT. The above shows only one series, but I ran many of them and the response timeout rate changes in the range 1% .. 5% depending on how congested the current environment is (WiFi/BLE other 2.4GHz stuff). I attribute the 0x22 reasons to this. On autoconnecting from my app (this time all MTU, connection, and notification requests in onServicesDiscovered commented out). At connect #247 the usual termination occured): 23:17:06.496 -> Conn: , CC=243 As you can see, another disconnect reason appeared 0x13 = Remote Host Terminated Connection, and quite a lot of it 37 out of 247 connections. 0x13 was not present in the device logs made with NRF Connect, and its origin is totally unclear to me (my Android app does not call cancelconnection for sure, I double checked). As previously pointed out, the time of disconnect always equals to the time of connect with each 0x13 reason, whereas in the 0x16 cases the difference is around 1100 ms (because 1000 ms after connecting I call disconnect on the current connection in the device). My conclusions: I can send you my app, but you would need the same firmware on the device as mine. Do you have access to any NRF52 board? If not, they can be purchased from 10 USD. I could help you get going. Thanks for your help! Peter |
Hello,
i am developing a BLE device based on an NRF52 chip to collect sensor data, and the android app to visualize them at the same time. So to speak, I am on both ends of the BLE connection.
The given sensor collects a lot of data (15 kB/s = 1.3 GB/day = ca. 40 GB/month). If I establish a connection and continuously stream one sensor's data to one Android device, this library works perfectly. Each BLE connection is stable (i.e. not interrupted) for months (!), probably longer (just not yet tested), and data flow is smooth.
Now, I want to test another scenario: one android device collects many nearby sensor's data (in the magnitude of 100). Because of BLE throughput limitation and with above mentioned data rate, only one or two devices can be allowed to be connected at a time only, so a lot of device connects and disconnects have to be performed. This works on both ends (BLE device and Android) well until ca. 200 - 300 connects/disconnects. After that, there is no error on either side, the Android BLE stack just stops working, as if it was overfloated. Even if I open an independent Android app with an independent sensor, the BLE stacks is dead. After an Android device restart, everything works again until the amount of connects/disconnects is reached.
In all these scenarios the BLE device is a peripheral and the Android side is the central, with later initiating the connection to the peripheral with autoconnect.
If I program the BLE device with a very simple program, that does nothing else but wait for a connection, and after 1 second initiate a local disconnect without any data transfer, I can reproduce this issue with just one BLE device and 200-300 connect/disconnect attempts to the very same device.
If I autoconnect to the same BLE device from NRF Connect Android app (this application is provided by the manufacturer of the chip to test BLE connections), everything works fine, no BLE stack overfloating occurs (tested up to ca. 10000 attempts).
Another observation is that with the Android BLE stack overfloated, the already opened connections continue to work (i.e. data transfer continues), just no new connections can be established.
I am ready to provide code samples (BLE device and Android) if needed.
Thanks for your help in advance!
P.
The text was updated successfully, but these errors were encountered: