Hamberthm / esp32-bt2ps2

Use a Bluetooth or BLE keyboard and mouse with your machine with a PS/2 port
MIT License
26 stars 6 forks source link

PIN for Pairing not displaying via Serial and LED #12

Closed MuadDib007 closed 1 month ago

MuadDib007 commented 1 month ago

I have downloaded and installed the 0.4 beta binary version to my ESP-WROOM-32 (Wemos D1 Mini32). It shows detection of many bluetooth devices including my Logitech Cordless Media Keyboard.

Unfortunately it does not snow a PIN via serial and the LED is not blinking as well. Tried to compile myself but as I am unexperienced with Visual Studio Code I fail to compile because it cannot find the includes.

Output from the serial: As I did not know the PIN I just entered a wrong one on the keyboard followed by ENTER

I (29) boot: ESP-IDF v5.1-rc2 2nd stage bootloader
I (29) boot: compile time Aug 17 2023 15:05:58
I (29) boot: Multicore bootloader
I (33) boot: chip revision: v1.0
I (37) boot.esp32: SPI Speed      : 40MHz
I (41) boot.esp32: SPI Mode       : DIO
I (46) boot.esp32: SPI Flash Size : 2MB
I (50) boot: Enabling RNG early entropy source...
I (56) boot: Partition Table:
I (59) boot: ## Label            Usage          Type ST Offset   Length
I (67) boot:  0 nvs              WiFi data        01 02 0000a000 00006000
I (74) boot:  1 phy_init         RF data          01 01 00010000 00001000
I (82) boot:  2 factory          factory app      00 00 00020000 00177000
I (89) boot: End of partition table
I (93) esp_image: segment 0: paddr=00020020 vaddr=3f400020 size=3a73ch (239420) map
I (188) esp_image: segment 1: paddr=0005a764 vaddr=3ffbdb60 size=045f8h ( 17912) load
I (196) esp_image: segment 2: paddr=0005ed64 vaddr=40080000 size=012b4h (  4788) load
I (198) esp_image: segment 3: paddr=00060020 vaddr=400d0020 size=c3fe4h (802788) map
I (492) esp_image: segment 4: paddr=0012400c vaddr=400812b4 size=16f1ch ( 93980) load
I (544) boot: Loaded app from partition at offset 0x20000
I (544) boot: Disabling RNG early entropy source...
I (555) cpu_start: Multicore app
I (556) cpu_start: Pro cpu up.
I (556) cpu_start: Starting app cpu, entry point is 0x40081360
I (0) cpu_start: App cpu up.
I (576) cpu_start: Pro cpu start user code
I (576) cpu_start: cpu freq: 160000000 Hz
I (576) cpu_start: Application information:
I (581) cpu_start: Project name:     esp32-bt2ps2
I (586) cpu_start: App version:      1
I (590) cpu_start: Compile time:     Aug 17 2023 15:05:44
W (681) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (698) coexist: coex firmware version: ebddf30
I (700) app_start: Starting scheduler on CPU0
I (705) app_start: Starting scheduler on CPU1
I (705) main_task: Started on CPU0
I (715) main_task: Calling app_main()
I (718) gpio: GPIO[23]| InputEn: 0| OutputEn: 1| OpenDrain: 1| Pullup: 0| Pulldown: 0| Intr:0 
I (727) gpio: GPIO[22]| InputEn: 0| OutputEn: 1| OpenDrain: 1| Pullup: 0| Pulldown: 0| Intr:0 
I (737) gpio: GPIO[2]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (987) BTDM_INIT: BT controller compile version [ad2b7cd]
I (992) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
E (1702) BTKeyboard: esp_ble_get_bond_device_list failed
BLE: a4:c1:38:70:a5:25, RSSI: -94, UUID: 0x0000, APPEARANCE: 0x0000, ADDR_TYPE: 'PUBLIC', NAME: 'ATC_70A525'
BLE: a4:c1:38:52:30:a2, RSSI: -90, UUID: 0x0000, APPEARANCE: 0x0000, ADDR_TYPE: 'PUBLIC', NAME: 'ihoment_H6199_30A2'
BLE: 6a:eb:25:22:1f:d9, RSSI: -62, UUID: 0xfe9f, APPEARANCE: 0x0000, ADDR_TYPE: 'RANDOM'
BLE: 3a:af:b4:13:86:8a, RSSI: -65, UUID: 0x0000, APPEARANCE: 0x0000, ADDR_TYPE: 'RANDOM'
BLE: 52:78:61:83:30:b1, RSSI: -62, UUID: 0xfe9f, APPEARANCE: 0x0000, ADDR_TYPE: 'RANDOM'
BLE: 68:8a:51:d2:fd:b9, RSSI: -80, UUID: 0xfe9f, APPEARANCE: 0x0000, ADDR_TYPE: 'RANDOM'
BLE: 0d:60:1e:31:a2:a5, RSSI: -43, UUID: 0x0000, APPEARANCE: 0x0000, ADDR_TYPE: 'RANDOM'
BLE: 60:68:bb:e6:95:b1, RSSI: -79, UUID: 0xfe9f, APPEARANCE: 0x0000, ADDR_TYPE: 'RANDOM'
BLE: f1:a0:95:83:85:77, RSSI: -89, UUID: 0x0000, APPEARANCE: 0x0000, ADDR_TYPE: 'RANDOM'
BLE: 72:43:3b:84:57:34, RSSI: -80, UUID: 0xfe9f, APPEARANCE: 0x0000, ADDR_TYPE: 'RANDOM'
BLE: 04:c0:5b:9f:88:70, RSSI: -79, UUID: 0x0000, APPEARANCE: 0x0000, ADDR_TYPE: 'PUBLIC', NAME: '04C05B9F886F'
BLE: 72:43:3b:84:57:34, RSSI: -67, UUID: 0x0000, APPEARANCE: 0x0000, ADDR_TYPE: 'RANDOM'
BLE: a4:c1:38:a4:4e:57, RSSI: -80, UUID: 0x0000, APPEARANCE: 0x0000, ADDR_TYPE: 'PUBLIC', NAME: 'ATC_A44E57'
BLE: a4:c1:38:f2:0a:ae, RSSI: -80, UUID: 0x0000, APPEARANCE: 0x0000, ADDR_TYPE: 'PUBLIC', NAME: 'ATC_F20AAE'
BLE: 67:bc:78:c0:b2:be, RSSI: -91, UUID: 0x3456, APPEARANCE: 0x0000, ADDR_TYPE: 'RANDOM'
BLE: a4:c1:38:38:49:4e, RSSI: -94, UUID: 0x0000, APPEARANCE: 0x0000, ADDR_TYPE: 'PUBLIC', NAME: 'ATC_38494E'
BT : 6c:0d:c4:6b:ff:38, COD: major: AV, minor: 9, service: 0x140, RSSI: -60, NAME: MIBOX4
BT : 00:07:61:b6:5e:0e, COD: major: PERIPHERAL, minor: 16, service: 0x001, RSSI: -54
BT : 00:07:61:b6:5e:0e, COD: major: PERIPHERAL, minor: 16, service: 0x001, RSSI: -51
BT : 00:07:61:b6:5e:0e, COD: major: PERIPHERAL, minor: 16, service: 0x001, RSSI: -54
BT : 00:07:61:b6:5e:0e, COD: major: PERIPHERAL, minor: 16, service: 0x001, RSSI: -50
BT : 22:22:25:42:69:2a, COD: major: AV, minor: 9, service: 0x140, RSSI: -88
BT : 6c:0d:c4:6b:ff:38, COD: major: AV, minor: 9, service: 0x140, RSSI: -60, NAME: MIBOX4
BT : 6c:0d:c4:6b:ff:38, COD: major: AV, minor: 9, service: 0x140, RSSI: -69, NAME: MIBOX4
BT : 6c:0d:c4:6b:ff:38, COD: major: AV, minor: 9, service: 0x140, RSSI: -63, NAME: MIBOX4
BT : 6c:0d:c4:6b:ff:38, COD: major: AV, minor: 9, service: 0x140, RSSI: -61, NAME: MIBOX4
BT : 00:07:61:b6:5e:0e, COD: major: PERIPHERAL, minor: 16, service: 0x001, RSSI: -52
BT : 6c:0d:c4:6b:ff:38, COD: major: AV, minor: 9, service: 0x140, RSSI: -72, NAME: MIBOX4
BT : 00:07:61:b6:5e:0e, COD: major: PERIPHERAL, minor: 16, service: 0x001, RSSI: -53
BT : 6c:0d:c4:6b:ff:38, COD: major: AV, minor: 9, service: 0x140, RSSI: -61, NAME: MIBOX4
BT : 00:07:61:b6:5e:0e, BDNAME: Logitech Cordless MediaBoard Pro(TM)
BT : 22:22:25:42:69:2a, BDNAME: TV-Vincent
  BT : 00:07:61:b6:5e:0e, RSSI: -53, USAGE: GENERIC, COD: PERIPHERAL[KEYBOARD] srv 0x001, UUID16: 0x0000, NAME: Logitech Cordless MediaBoard Pro(TM) 
I (11033) BTKeyboard: Waiting for BT manual code entry...
I (12034) BTKeyboard: Waiting for BT manual code entry...
W (12299) BT_HCI: hcif conn complete: hdl 0x81, st 0x0
W (12444) BT_SDP: process_service_attr_rsp

W (12805) BT_SDP: process_service_attr_rsp

I (13034) BTKeyboard: Waiting for BT manual code entry...
I (14034) BTKeyboard: Waiting for BT manual code entry...
I (15034) BTKeyboard: Waiting for BT manual code entry...
E (15495) BT_BTC:  btc_dm_auth_cmpl_evt() Authentication fail reason 5
W (15523) BT_BTM: btm_sec_clr_temp_auth_service() - no dev CB

W (15527) BT_HCI: hci cmd send: disconnect: hdl 0x81, rsn:0x13
E (15529) BT_HIDH: OPEN ERROR: ERR_AUTH_FAILED
E (15531) BTKeyboard:  OPEN failed!
E (15591) BT_BTM: Device not found

W (15592) BT_HCI: hcif disc complete: hdl 0x81, rsn 0x16
E (15593) BT_APPL: bta_gattc_mark_bg_conn unable to find the bg connection mask for: 00:07:61:b6:5e:0e
I (16034) BTKeyboard: Waiting for BT manual code entry...
I (17034) BTKeyboard: Waiting for BT manual code entry...
I (18034) BTKeyboard: Waiting for BT manual code entry...
Hamberthm commented 1 month ago

Hi there! Thanks for reporting this and for posting the log.

It seems your Mediaboard Pro is an older model that uses the Legacy Pairing procedure. This protocol requires the user to enter a custom pairing key on the device, then the device informs the keyboard about it.

Since we can't enter a custom pin easily on the ESP32, this key is fixed and is always 1234, as defined in bt_keyboard.cpp:

  /*
   * Set default parameters for Legacy Pairing
   * Use fixed pin code
   */
  esp_bt_pin_type_t pin_type = ESP_BT_PIN_TYPE_FIXED;
  esp_bt_pin_code_t pin_code;
  pin_code[0] = '1';
  pin_code[1] = '2';
  pin_code[2] = '3';
  pin_code[3] = '4';
  esp_bt_gap_set_pin(pin_type, 4, pin_code);

Please try to use 1234 as a pin then enter when you read " Waiting for BT manual code entry..." on the console!

Remember to use this procedure to make your keyboard discoverable:

Switch the keyboard off, switch it on, press reset. (source)

I might as well put this on the readme on the mainpage. Sorry, I don't have a legacy keyboard so I didn't know this could happen!

Humberto

MuadDib007 commented 1 month ago

Hi Humberto, thanks for the quick response.

Using 1234 as pin works perfectly. Can't wait to test it on my "old" computer.

Hamberthm commented 1 month ago

That's great! Glad it worked. I'm going to put this on the readme.

Remember to build your cable with care and to configure the pins correctly.

A new version is coming with support for multimedia keys. Once you got v0.4 working, if you are interested in testing it check #7 .

If anything goes wrong and you need help, please open a new issue.

Cheers!