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

HID Keyboard - Problems After Disconneting and Downloading

Environment :

  • Custom Board with MCU NordicSemi nRF51822-QFAA

  • Softdevice S110 7.1

  • IAR for ARM 7.1

  • SDK 7.2 using HID keyboard example + testing with iPhone 5S, 6 and iPad air (iOS 8.1.3)

/ Nexus 5 and Galaxy Note 3 (Android 4.4.2).

/***************************************************************************************/

After the iOS devices connect with the HID peripheral, the examples works.

  • First, while the phone and the peripheral are bonded,

I did "Settings -> Bluetooth -> Bluetooth Off", so the BLE_EVT_DISCONNECT has occurred.

image description

(I pressed the button which is pointed by a red arrow.)

Since I didn't deleted the peripheral on the "Settings" list, it will be connected

due to direct advertising mode.

So, when the peripheral is connected by direct advertising mode, the example code still works.

The meaning of working is, when I press the button 6 times, it sends h, e, l, l, o , and return.

Also, the virtual keyboard does not appear after I press the button.

image description

  • Second, this is the problem I faced.

If I didn't turned off the Bluetooth and (instead) deleted the device from the

"Settings -> Bluetooth -> Devices", the HID peripheral falls into the BLE_EVT_DISCONNECT.

image description

When I try to bond again together, the bonding seems to be fine. However,

the virtual keyboard pops up and when I press the button, the string does not shows up.

image description

(As you see, the red box shows that the phone is connected with the peripheral.

However, the keyboard shows up and the string "hello" does not appear.)

This phenomenon also appears when I test with the Android devices as well.

  • Third, after I download the code several times (7 to 8 times or sometimes more), the connection keeps fails.

Plus, in this case, the iPhone shows connection error number 6 which is timeout error.

(ref :

developer.apple.com/.../index.html

)

image description

(The link was provided by Petter Myhre. Thanks for always helping me Petter :D )

In this case, I erased the flash by nRFgo and burned the flash again.

/***************************************************************************************************************************************************************************/

In short, when the phone and the peripheral is connected by direct advertising,

it works fine, but when it is connected again after deleting the device from the settings menu,

it does not work properly.

Also after several downloads sometimes the connection fails even

though the code hasn't changed.

What could be the problem? Does the BLE stack gets tangled up?

-Regards, Mango922

  • The ble_app_hids_keyboard application can handle 7 bonds (DEVICE_MANAGER_MAX_BONDS 7).

    When you press "Forget This Device" you will erase the bonding information on the phone, but it will still be on the peripheral. If you don't delete it on the peripheral I'm not entirely sure what will happen, either will add a new bond and work, or it will believe it is already bonded and not work.

    Downloading the code will not erase the bonding information, so after 7 or 8 downloads you will have 7 or 8 bonds stored (if you bond every time), since 7 is max I think this is when you get the issue.

    The bonding information can be erased by checking "Erase Full Chip" in Options for Target->Utilities->Settings->Flash Download or by pressing a certain button on startup:

    // Clear all bonded centrals if the "delete all bonds" button is pushed.
    err_code = bsp_button_is_pressed(BOND_DELETE_BUTTON_ID,&(init_data.clear_persistent_data));
    APP_ERROR_CHECK(err_code);
    

    Edit 19.02: Removed a Bluetooth symbol mistake.

    Edit 20.02: I have been able to reproduce this; I think it is an iOS bug. The peripheral actually adds a new bond, and it is sending key presses, but iOS is not responding to them. We will investigate further, but you should report this to Apple. I will edit this answer if there are any updates from our side.

    There is a reason that comes with the BLE_EVT_DISCONNECT event, but it is the same reason if you turn off Bluetooth or press Forget this device, so you can't separate them.

    If you always delete the bonding information there is really no reason to store it persistently, anyways, you should look into dm_init(). Please add this as a new question if anything is unclear.

    One more thing, you shouldn't use directed advertising with iOS since it is changing it's address every 15 minutes.

  • Thank you for checking the Bluetooth mark.

    The not working situation cannot be explained yet?

    Also, whether I select "Forget the device" or Bluetooth off,

    the HID peripheral falls into disconnect event.

    However there is no way that the peripheral to tell which was selected(forget device/bluetooth off)

    from the phone?

  • One more thing, without using this,

    err_code = bsp_button_is_pressed(BOND_DELETE_BUTTON_ID,&(init_data.clear_persistent_data));
    APP_ERROR_CHECK(err_code);
    

    how can I delete it regardless of the button press?

    What other function do I have to call?

    Edited : I see. Although the same problem seems to appear when I test with Android devices,

    I'll ask to th Apple dev page. Thank you.

  • On Android as well? I didn't catch that. I tested it on my Samsung Galaxy Note 4 (4.4.4) and Samsung Galaxy Note 2 (4.4.2), and it works. Can you please test again?

  • When I test with Nexus 5 (4.4.2), it is fine.

    However when I test with Galaxy Note 3 (4.4.2), it sometimes doesn't work properly.

Related