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

Can't read characteristics of BLE HID service example

I'm trying to implement the HID service on a custom nrf52832 board, unfortunately I'm running into problems.

Here's what happens: Advertising, connecting to the board, service discovery, GPIOs (buttons & LEDs), reading the battery level, etc. all work great. I use nRF Connect to test this. However when trying to read HID characteristics (except for the protocol mode), the operation never finishes (the spinner keeps spinning). The log does not show any errors or other entries, except for the battery service updates that keep coming in. When I hit disconnect the spinner stops and the device is discoverable again.

The same happens when I use the "enable all services" menu item like described in the example. The HID device also doesn't produce any input in Android, even when connecting through settings and enabling "use for input device").

At first I suspected problems in my code, but now I'm running the unmodified examples (with -DBOARD_CUSTOM though) and have the exact same issue. I tried both the HID mouse and keyboard example. I'm using version 12.2 of the nRF5 SDK, though I'm getting the same result with 12.0.

Any ideas what's going wrong? I'd also appreciate any hints on how to further debug this.

Parents
  • FormerMember
    0 FormerMember

    When I test here, the HID example, ble_app_hids_keyboard (SDK 12.2.0, S132, v3.0.0), works fine. I don't see the behavior that you describe. Could you try the same hex file as I am using, and check if that hex file results in the same problem on your side: ble_app_hids_keyboard.hex (the hex file uses external LFCLK crystal as LFCLK clock source)

    Update 06.02.2017:

    After a closer look at the keyboard example, I see that the scheduler is only being used for the simulated battery measurement updates..

    I now think I understand what you mean. I re-tested: I connected my phone to the advertising keyboard using nRF Connect. When I then enabled the "report" characteristics, there was a disconnect. Looking at the log in nRF Connect, the disconnect occured due to a "Blueooth priviledged" permission. From this blog post, chapter 4.6, it happened because HID is in-built in Android naively.

    Therefore, please try the following: Connect to the keyboard device from the Bluetooth setting in the Settings menu on the phone. At the top bar on the phone there will be instructions on how to proceed (connect properly).

    To test that the keyboard is working (using a nRF52-DK), put the phone cursor in a search window, press button 1, and see that 'hello' will be written.

  • FormerMember
    0 FormerMember in reply to FormerMember

    Yes, the commented NRF_LOG(...) in app_error.h seems to be commented by a mistake. I think they can be uncommented.

  • Hi whats need to change for random passkey please help me i modified the code like below but central is not connecting.

    #define SEC_PARAM_BOND 1 /**< Perform bonding. */
    #define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */
    #define SEC_PARAM_LESC 1 /**< LE Secure Connections not enabled. */
    #define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */
    #define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_KEYBOARD_ONLY

    #define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */
    #define SEC_PARAM_MIN_KEY_SIZE 7 /**< Minimum encryption key size. */
    #define SEC_PARAM_MAX_KEY_SIZE 16

    static void gap_params_init(void)
    {
    uint32_t err_code;
    ble_gap_conn_params_t gap_conn_params;
    ble_gap_conn_sec_mode_t sec_mode;

    // BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
    BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&sec_mode);

    err_code = sd_ble_gap_device_name_set(&sec_mode,
    (const uint8_t *) DEVICE_NAME,
    strlen(DEVICE_NAME));
    APP_ERROR_CHECK(err_code);

    memset(&gap_conn_params, 0, sizeof(gap_conn_params));

    gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
    gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
    gap_conn_params.slave_latency = SLAVE_LATENCY;
    gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT;

    err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
    APP_ERROR_CHECK(err_code);

    ble_gap_opt_t gap_opt;

    gap_opt.passkey.p_passkey = (uint8_t *)NULL;

    err_code = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY,(const ble_opt_t *)&gap_opt);
    APP_ERROR_CHECK(err_code);
    }

Reply
  • Hi whats need to change for random passkey please help me i modified the code like below but central is not connecting.

    #define SEC_PARAM_BOND 1 /**< Perform bonding. */
    #define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */
    #define SEC_PARAM_LESC 1 /**< LE Secure Connections not enabled. */
    #define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */
    #define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_KEYBOARD_ONLY

    #define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */
    #define SEC_PARAM_MIN_KEY_SIZE 7 /**< Minimum encryption key size. */
    #define SEC_PARAM_MAX_KEY_SIZE 16

    static void gap_params_init(void)
    {
    uint32_t err_code;
    ble_gap_conn_params_t gap_conn_params;
    ble_gap_conn_sec_mode_t sec_mode;

    // BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
    BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&sec_mode);

    err_code = sd_ble_gap_device_name_set(&sec_mode,
    (const uint8_t *) DEVICE_NAME,
    strlen(DEVICE_NAME));
    APP_ERROR_CHECK(err_code);

    memset(&gap_conn_params, 0, sizeof(gap_conn_params));

    gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
    gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
    gap_conn_params.slave_latency = SLAVE_LATENCY;
    gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT;

    err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
    APP_ERROR_CHECK(err_code);

    ble_gap_opt_t gap_opt;

    gap_opt.passkey.p_passkey = (uint8_t *)NULL;

    err_code = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY,(const ble_opt_t *)&gap_opt);
    APP_ERROR_CHECK(err_code);
    }

Children
No Data
Related