keep getting NRF_ERROR_INVALID_STATE when trying to send key via HID

Hey,

I have an app based on the UART central example. I successfully connect and bond to an android and am able to send data via uart over BLE.

I want to send data also via HID over BLE as demonstrated in the peripherial example of ble_app_hids_keyboard_pca10056_s140.

With the example I connect and bond my android and am able to see "hello" printed in a notebook app.

I merged that example to my app, but in my app after I connect and bond, I always fail while I try sending the key with ble_hids_inp_rep_send() that calls sd_ble_gatts_hvx() that always returns NRF_ERROR_INVALID_STATE error code.

I saw the documentation saying:

 * @retval ::NRF_ERROR_INVALID_STATE One or more of the following is true:

 *                                   - Invalid Connection State
 *                                   - Notifications and/or indications not enabled in the CCCD

 *                                   - An ATT_MTU exchange is ongoing

and because I'm sure connection state is fine I assume it's the CCCD problem but I don't really understand why it happens and how to fix it.

does anyone know hoe I shall proceed?

Thanks,

Robbie

Parents
  • Hi Robblev, 

    Could you give more information about your application ? 
    Do you plan to make a BLE keyboard or you simply want to use HID to transfer data ? 
    HID is a special service and it's handled by the Android OS directly. If you connect to a HID device either by the Bluetooth or via your app, the OS will automatically bond and you won't be able to access the HID service from your app. 
    However it's possible to access other services on the device from your app. 

    Have you tried to test with the unmodified ble_app_hids_keyboard ? 

  • Thanks for the response,
    I'll explain myself better though I now think it's an android question and not a nordic one:

    I have an app using the nordic board as central, I connect, pair and bond to an android phone.

    I want to be able to write via HID on the android. I'm able to do it when the board is a peripheral device (like in the ble_app_hids_keyboard example) and the android finds the board's advertisement and bonds to it. BUT I want the nordic board to be the central and not advertise at all. the board scans for the android's advertise and bonds to it but in this case I don't have the CCCD of the android to send HID keys. I wonder if all I need is for the android to discover the nordic's gap and then I think I will have the CCCD for HID.
    Does this make sense?

  • Hi Robblev, 
    I think I understood what you wanted to do. However HID is a special service so I'm not sure if it would act the same when you are doing peripheral on the phone. 
    If you use other service it would be quite simple to do so. Please note that the CCCD is belong to the GATT server. It's where the service is declared. It doesn't matter if it's a central or peripheral. The server can be declared on either central or peripheral. 

Reply
  • Hi Robblev, 
    I think I understood what you wanted to do. However HID is a special service so I'm not sure if it would act the same when you are doing peripheral on the phone. 
    If you use other service it would be quite simple to do so. Please note that the CCCD is belong to the GATT server. It's where the service is declared. It doesn't matter if it's a central or peripheral. The server can be declared on either central or peripheral. 

Children
Related