This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

keeping connection alive for long times

Hello,

I am using the nRf8001 and successfully connecting to an android device, but I still have some doubts related to the BLE protocol itself, specifically to the connection interval.

Suppose I want to send some data to the central device once per minute. According to what I understood, if I spend more time than what is in "Connection supervision timeout" field the connection will be dropped. So I should constantly reconnect to the device from the app side, is that correct? Is there any more elegant way to keep the connection alive without sending data at smaller intervals from the peripheral? (my application has tight power requirements).

That said, I've noted that even with "Connection supervision timeout"=100ms the device keep connected for 7~8 min before the connection is dropped, even without sending any data (Does the BLE have any link-layer keepalive mechanism?). But sometimes it disconnected after only a few seconds. And in another android device it always disconnect after a few seconds.

I've also noted that when the device goes out of range, the disconnection error code is 0x08 (timeout). So, when the device disconnects after a few seconds, I can´t be sure if I have a hardware problem in my RF circuit or a software problem. Is there some flag to indicate my disconnection was caused by a signal loss?

In summary, whats the best way to keep the connection alive and what is the expected behavior so I can I find out if I am having a hardware or a software problem?

Thanks in advance,

  • Which Android device are you connecting to? Do not rule out the phone itself as there are several Android phones (even high end ones; Nexus 4, HTC One M8) which have trouble keeping a BLE connection for long. Also which version of Android does this phone have?

  • Hi Locky, Do you think the correct behavior would be to the connection be maintained even without data transfer? I've tried it with Sony Z2 and M2 Aqua, both running Android 4.4.4 and a Galaxy S"x" with Kitkat (I dont remember the exact model and Android version, and I'm not with the phone here right now). Regards

  • Hi Jaciroscar,

    Could you give me more information on the connection parameters (connection interval, slave latency, connection timeout) that you used for your device ?

    If you have connection timeout = 100ms and if you have connection interval = 35ms for example, the connection may be timed out if there are 3 packets drop. This could very easily happens if there is some interference. If you can provide a sniffer trace, it would be useful.

    I do agree that it's not very stable on some Android phones to keep the connection for a long time, but I'm talking about several hours or days not just few minutes as in your case.

  • Hi Hung Bui, Unfortunatelly I don´t have a packet snnifer. Just to confirm, even without data transfer, the connection should be kept alive for hours/days ideally? My current parameters are Maximum connection interval=22.5ms; Minimum connection interval=12.5ms; Slave latency=0; Connection Supervision timeout=100ms.

  • Yes, by theory even without any activity the connection should be kept. (Empty payload packets are automatically sent on every connection event to keep the connection) Your supervision timeout is pretty short if there are only several packet drop it would cause connection timeout.

    And please noted that the maximum and minimum connection interval is only used as the preferred request from peripheral, it depend on the central to decide which connection interval will be used. So there is a chance the actual connection interval is not between 12.5ms and 22.5ms (with most Android phone it won't be in that range). I would suggest you to change supervision timeout to 1 to 4 seconds for example.

Related