No Disconnect or Connection supervision timeout

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Panometric
Level 5
Level 5
100 sign-ins 100 replies posted 10 solutions authored

My issue is that the BLE device does not see a disconnect.

Using the USB HID Keyboard Demo,  with some modifications. There is no BLE sleeping, and the main loop is using CySysPmSleep() which is woke by a 1mS hardware interrupt from a timer.  Therefore, CyBle_ProcessEvents() is called at least every ms.    BLE version is current: 3.52

Scenario:

  • Connect
  • Use Battery Service
  • Backout of Android app until phone says "Device is disconnected"

Expectation: BLE Stack should indicate CYBLE_EVT_GAP_DEVICE_DISCONNECTED or CYBLE_EVT_TIMEOUT, depending on whether it heard the disconnect message. The connection state should change and it should go back to advertising.

Auto come: Neither event happens and stack continues to say CyBle_GetState() == CYBLE_STATE_CONNECTED is true forever.

What am I doing wrong? Thanks.

Log Output

> BLE Upgradable Stack HID Keyboard

> Version: 1.20

> Compile Date and Time: Jul  6 2018 10:15:29

Bluetooth On, StartAdvertisement with addr: 00a050000615

CYBLE_EVT_ADVERTISING, state: 3

CYBLE_EVT_GATT_CONNECT_IND: 0, 4

CYBLE_EVT_GAP_DEVICE_CONNECTED

CYBLE_EVT_CONNECTION_UPDATE_COMPLETE: 0

CYBLE_EVT_AUTH_FAILED: 6

CYBLE_EVT_GATTS_XCNHG_MTU_REQ, final mtu= 23

CYBLE_EVT_CONNECTION_UPDATE_COMPLETE: 0

CYBLE_EVT_CONNECTION_UPDATE_COMPLETE: 0

CYBLE_EVT_GATT_DISCONNECT_IND

CYBLE_EVT_GAP_DEVICE_DISCONNECTED

CYBLE_EVT_ADVERTISING, state: 3

CYBLE_EVT_GATT_CONNECT_IND: 0, 4

CYBLE_EVT_GAP_DEVICE_CONNECTED

SimulBatteryLevelUpdate: 2

CYBLE_EVT_CONNECTION_UPDATE_COMPLETE: 0

CYBLE_EVT_GATTS_XCNHG_MTU_REQ, final mtu= 23

CYBLE_EVT_CONNECTION_UPDATE_COMPLETE: 0

SimulBatteryLevelUpdate: 2

OTHER event: 57

OTHER event: 33

CYBLE_EVT_AUTH_REQ: security=3, bonding=1, ekeySize=10, err=0

CYBLE_EVT_CONNECTION_UPDATE_COMPLETE: 0

CYBLE_EVT_GAP_ENCRYPT_CHANGE: 1

CYBLE_EVT_GAP_KEYINFO_EXCHNGE_CMPLT

AUTH_COMPLETE: security:1, bonding:1, ekeySize:10, authErr 0

OTHER event: fa

CYBLE_EVT_CONNECTION_UPDATE_COMPLETE: 0

OTHER event: 104

CYBLE_EVT_CONNECTION_UPDATE_COMPLETE: 0

OTHER event: 57 //Manual Read

CYBLE_EVT_CONNECTION_UPDATE_COMPLETE: 0

SimulBatteryLevelUpdate: 2

SimulBatteryLevelUpdate: 2

CYBLE_EVT_CONNECTION_UPDATE_COMPLETE: 0  // Only indication of phone disconnecting

CYBLE_EVT_CONNECTION_UPDATE_COMPLETE: 0

SimulBatteryLevelUpdate: 2  // Should never happen - no longer connected.

SimulBatteryLevelUpdate: 2

SimulBatteryLevelUpdate: 2

SimulBatteryLevelUpdate: 2

0 Likes
1 Solution

Hello Mike,

1) This is not CySmart App issue. App is sending disconnect request to the Phone BLE stack on closing the App but BLE stack is not processing this request. The issue persists with other BLE Mobile Apps as well and not only with CySmart App.

2) Yes , you can call CyBe_GapDisconnect() API to disconnect from the Mobile Phone when there are no useful BLE activities.

-Gyan

View solution in original post

6 Replies
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Hello Mike,

Can you please send your design. We can see the issue and modify the changes if needed.

Thanks,

PSYU.

0 Likes
lock attach
Attachments are accessible only for community members.

psyu​ here is a demo of the issue.  Note the issue is only confirmed on a a Nexus 6 with Android 7.0

gyan​ I tried a Pixel 1 XL and it does not seem to have the problem.

Therefore, we can probably narrow the issue to not disconnecting after a connection timeout.  My goal in restructuring the main loop is to keep the BLE working, but never goto sleep or waste too much effort on it, since for my design BLE is not the primary feature. My understanding from the data sheet is as long as I call ProcessEvents faster than the connection interval which is 7ms minimum, BLE should be fine. If that is not the case please clarify.

Thanks.

0 Likes

Hello Mike,

    Connection supervision timeout is a parameter that defines the maximum time between two received Data Packet PDUs before the

connection is considered lost. This is a link layer timer and application does not have  any control over it. If the devices does not receive a BLE packet for a time equal to Connection supervision timeout value , the link will lost the connection.

The issue here is some mobile phones , where even if you disconnect or kill the app ,the mobile hardware will maintain the connection with peer BLE device and hence the mobile neither sends a Disconnect request Nor Connection supervision timeout happens.

Yes, you are right. We should call CyBle_ProcessEvents() at least once in a connection interval to process the BLE events.

-Gyan

0 Likes

Gyan,

You are right, using a sniffer, I was able to confirm that the Phone App says the device is disconnected, but the phone continues to keep the connection open, exchanging empty PDUs. So then I turned bluetooth off in the phone, and that actually disconnected by BLE opcode from  the phone. Interestingly, it sent two terminate opcodes.

Remember, this happens only when you use the battery service. So this suggests that phone stack is trying to maintain two logical connections, and only disconnects one of them.

Two Questions:

1. Is this potentially a bug in the Cysmart app rather than the Android OS not killing the channel it opened to get the battery notifications before disconnecting?

2. Regardless, assume this is an open eco-system application and the phone cannot be fixed, this would be a battery killing bug. The device should not allow that. Is there a workaround for forcing a disconnection from the device if no useful activity has occurred for some time? How might that be done in the Cypress API?

Hello Mike,

1) This is not CySmart App issue. App is sending disconnect request to the Phone BLE stack on closing the App but BLE stack is not processing this request. The issue persists with other BLE Mobile Apps as well and not only with CySmart App.

2) Yes , you can call CyBe_GapDisconnect() API to disconnect from the Mobile Phone when there are no useful BLE activities.

-Gyan

GyanC_36
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

Hello MikeMitchell ,

     Which Mobile Phone are you using?

There is issue with some mobile phone's BLE hardware and they do not send a Disconnect Request even after closing the APP and keeps BLE connection maintained in background.

Could you try with some other Mobile phones and CySmart BLE USB Dongle with CySmart Windows PC tool?

-Gyan

0 Likes