HID host with IDF and Arduino

Craig02445
Posts: 1
Joined: Mon Jan 03, 2022 4:39 pm

HID host with IDF and Arduino

Postby Craig02445 » Mon Jan 03, 2022 4:53 pm

I need to run the esp_hid_host demo in the Arduino environment. I need to add:

Code: Select all

#define CONFIG_BT_HID_HOST_ENABLED 1
to the Arduino sdkconfig.h file (the one that says "DO NOT EDIT" but alas ...) and I add the setup() and loop() where setup simply calls app_main(). The loop() is empty. It is also necessary to add

Code: Select all

#include "BLEUUID.h"
It compiles and runs to the point where the scan detects a Bluetooth keyboard. Unlike when it runs when built in the IDF environment, it does not go past this point whereas the IDF version goes on to (apparently) pair and the hidh_callback shows the HID data. The Arduino output is simply:

Code: Select all

[   539][I][esp_hid_host_main.ino:83] hid_demo_task(): SCAN...
[  5656][I][esp_hid_host_main.ino:86] hid_demo_task(): SCAN: 1 results
  BT : 21:14:a5:86:81:b8, RSSI: -92, USAGE: GENERIC, COD: PERIPHERAL[KEYBOARD] srv 0x001, , NAME: iClever IC-BK04 Keyboard 
and stops whereas the IDF output (in part) shows:

Code: Select all

I (7619) ESP_HIDH_DEMO: 21:14:a5:86:81:b8 OPEN:
BDA:21:14:a5:86:81:b8, Status: OK, Connected: YES, Handle: 0, Usage: KEYBOARD
Name: , Manufacturer: , Serial Number:
PID: 0x7021, VID: 0x04e8, VERSION: 0x011b
Report Map Length: 295
  CCONTROL   INPUT REPORT, ID: 255, Length:   1
  CCONTROL   INPUT REPORT, ID:   5, Length:   1
   GENERIC   INPUT REPORT, ID:   4, Length:   1
  CCONTROL   INPUT REPORT, ID:   3, Length:   7
  CCONTROL   INPUT REPORT, ID:   2, Length:   3
  KEYBOARD  OUTPUT   BOOT, ID:   1, Length:   1
  KEYBOARD  OUTPUT REPORT, ID:   1, Length:   1
  KEYBOARD   INPUT   BOOT, ID:   1, Length:   8
  KEYBOARD   INPUT REPORT, ID:   1, Length:   8
I (7699) ESP_HIDH_DEMO: 21:14:a5:86:81:b8 INPUT: CCONTROL, MAP:  0, ID:   3, Len: 7, Data:
I (7699) ESP_HIDH_DEMO: 64 21 14 a5 86 a0 b9
I (7709) ESP_HIDH_DEMO: 21:14:a5:86:81:b8 INPUT: KEYBOARD, MAP:  0, ID:   1, Len: 8, Data:
I (7709) ESP_HIDH_DEMO: 00 00 09 00 00 28 b5 fb
Any idea where I need to look next or hints are moving forward. I have no code in the Arduino loop().
Thanks for any feedback.

zian31
Posts: 1
Joined: Sun Jul 02, 2023 7:47 pm

Re: HID host with IDF and Arduino

Postby zian31 » Sun Jul 02, 2023 8:03 pm

Hi !
I've tried the same thing with this code :
https://github.com/espressif/esp-idf/tr ... p_hid_host
Replacing "esp_hid_host_main.c" with "esp_hid_host_main.ino"

And I add ESP32 2.0.1 library to Arduino IDE => also adding the define "#define CONFIG_BT_HID_HOST_ENABLED 1" in the sdkconfig.h
With newer ESP32 libraries, sdkconfig.h are more than just one, so hard to know which one to modify.

This line was never executed :

Code: Select all

esp_hidh_dev_open(cr->bda, cr->transport, cr->ble.addr_type);
So I change it to "esp_hidh_dev_open(r->bda, r->transport, r->ble.addr_type);" without the "while (r)" and "if (cr)" and add printf for informations :

Code: Select all

printf("Opening: %s: " ESP_BD_ADDR_STR ", [%s]\n", (r->transport == ESP_HID_TRANSPORT_BLE) ? "BLE" : "BT ", ESP_BD_ADDR_HEX(r->bda), r->name ? r->name : "");
esp_hidh_dev_t *p_dev = esp_hidh_dev_open(r->bda, r->transport, r->ble.addr_type);
printf("esp_hidh_dev_open returned %d\n", p_dev);
It's also returning :
SCAN: 1 results
BT : xxx, RSSI: -xx...

And the last result is "esp_hidh_dev_open returned 0".
So it's not working too... for the moment.

This Github can help to find the solution :
https://github.com/StryderUK/BluetoothHID

Who is online

Users browsing this forum: No registered users and 72 guests