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

HID reconnection problem

I'm trying to save power on my HID keyboard application by disconnecting the Bluetooth link after some time of inactivity. As soon as there are keystrokes to send, the device advertises again and sends the pending values.

Generally I have 8 chars to transmit at once, but in Android 7.1.1 (Nexus 5X) I often get only 7 or less. The first one or two characters seem to get lost, although there is no error event generated by my nRF8001. I even get the right number of data credit events, so I assume the values have been sent correctly. The second value (again 8 chars) is always transmitted entirely.

I always wait for the first pipe status event after reconnection, sending data right after the connected event makes it even worse.

How can I achieve a reliable transmission of my first value? Is there some event to tell me that the master device is fully ready to receive keystrokes? Has someone experienced a similar behaviour and found a workaround?

  • Are you bonding to the peer? In this case you should be able to send notifications immediately after reconnecting.

    If you are not bonded, you have to wait until the cccd's are enabled by the peer. However, you should get a PipeErrorEvent response from the nRF8001 if you try to send notifications when they are disabled. And I assume you see that the credits are used. Might be some issue with Android, so you have to wait for some time before sending the notifications. Do you have a sniffer trace that shows what is happening on air?

  • Yes, I use a bonded connection. The first pipe status event shows that all previously opened pipes are still available. When sending keystrokes directly after the connected event, there are even more devices that do not display all of them. An iPad mini with iOS8.1 misses my first 2 or 3 characters, the Nexus 5X even up to 5 chars...

    For information: All the tests are done with the Nordic ble_HID_keyboard_template.

    I have an nRF51822 dongle (PCA10000) that should work as a sniffer, but I can't get it to work. Is there an updated version that would work with the actual version of wireshark (2.2.5)?

  • You should use version 1.10.x of wireshark for the sniffer. I'm sorry it's not more up to date.

  • Finally I managed to get a trace with the sniffer. Had to downgrade the Segger firmware on the PCA10000 dongle as described here: Sniffer not working PCA10000

    image description

    As you can see, the connection is initiated at frame no 1965. The first notification is sent in frame 1969, but the master is still requesting some information. In this case the first 11 notification packets were not handled (characters not displayed) by the master. Is it allowed to ignore these first notifications? What should I do to be sure all my keystrokes are handled correctly?

  • You need to encrypt to re-establish the bond before you can start sending notifications. The Master doesn't recognise the peer until the LTK is verified, i.e. it doesn't know that this is a bonded peer and that notifications are enabled.

Related