[RPi5] Trying to get bluetooth remote "OK" button to send an "ENTER" code?

  • I've been using a Rii-25 wireless remote - it's a piece of crap. I foolishly purchased another one and it, too, is a piece of crap. The issue is horrible keybounce, you simply CANNOT get a key to fire only ONCE - it's always two or ever three times. Like Neil Young sings, "Piece of CRAP!"

    So, having a new RPi5 with built in bluetooth capabilities, I took a chance on a simple UGOOS BT Remote Control UR02 from Ali Express.. I figured I could risk $12 US.

    I received the remote, I got it to pair, and BINGO - it works - it works and the keys DO NOT BOUNCE.. Happy dance!

    Except...

    The OK key the center of the click wheel doesn't do anything. Well, lets modify that, it will wake Kodi from the screen saver, so I know it WORKS and is sending something, but I can't use it to select menu items. Time to search the forums!

    In this thread, 26261-fix-for-xiaomi-bluetooth-remote-with-nonworking-button, there is a description of a fix that includes two lines, an EVDEV identifier (?) string and then a KEYBOARD_KEY remap statement included in one of the init files:

    Quote

    Couldn't get evtest working, but got enough information from running cat /proc/bus/input/devices

    Created the 70-local-keyboard.hwdb file with the code below and it worked OK <3

    Code
    evdev:input:b0003v4842p0001*
     KEYBOARD_KEY_c0041=enter

    In theory, I should be able to use "/storage/.kodi/addons/virtual.system-tools/bin/evtest" or "cat /proc/bus/input/devices" to help me figure out the input device, then remap the code to effect an "enter" action. That's my interpretation at any rate. I reviewed more than one forum entry and this seems like this is a common issue with Blutooth remotes. Some entries refer to this work around and some are just dead threads, but in threads with a solution all the input devices appear to have a unique "evdev:input:$STRING" entry. So how do I find this identifier as it relates to my cheap little remote? (that does NOT suffer keybounce!) 8o

    Running evtest doesn't show me anything that looks like my BT remote: (only shows the HDMI and RPi5 power button)

    Code
    Livingroom:~ # evtest
    No device specified, trying to scan all of /dev/input/event*
    Available devices:
    /dev/input/event0:    vc4-hdmi-0 HDMI Jack
    /dev/input/event1:    vc4-hdmi-1 HDMI Jack
    /dev/input/event2:    pwr_button
    Select the device event number [0-2]:
    ^C
    Livingroom:~ #

    Likewise, viewing /proc/bus/input/devices doesn't reveal anything useful to me: (again, only showing data pertinent to the HDMI ports and the integral RPi5 power switch)

    I'm feeling a little lost here... I THINK the work around is right at my finger tips, but for the life of me I can't seem to put it all together.

    I wonder if anyone has a clue how I should proceed, SPECIFICALLY, how I determine the "evdev:input:$STRING" that would apply to my bluetooth device.

    Thanks so much for any and all input!

    Sincerely,

    -ET-

  • Reboot. Once the home screen shows, SSH in and run"journalctf -f", then fiddle with buttons on the remote so it reconnects; which should be visible and obvious in the journal. Once the remote is connected, run "cat /proc/bus/input/devices" and you should now see the input devices registered by the remote. I think the current issue is simply that when the RPi5 is booted the BT remote is not automatically reconnected (until you press buttons) so there is correctly no input device listed.

    True ??

  • Thank you, Chewitt!

    That got me a little further, but I'm not 100% sure how or if I can use the information gleaned. First, here's the output of "evtest" after a clean reboot, then running "journalctf -f"


    I think the key here is:

    Code
    Input device ID: bus 0x5 vendor 0x508 product 0x1980 version 0x0
    AND from "cat /proc/bus/input/devices" 
    S: Sysfs=/devices/virtual/misc/uhid/0005:0508:1980.0001/input/input4

    ...which sort of matches this format;

    Code
    evdev:input:b0003v4842p0001*

    ..ie; a bus, a vendor and a product:

    "evdev:input:b0005v0508p1980*"

    But now I'm confused about the keycode part? grep'ing on "enter", I see:

    Code
    Select the device event number [0-4]: 3
       Event code 28 (KEY_ENTER)
       Event code 96 (KEY_KPENTER)
    ^C
    Livingroom:~ #
    Code
    (the example code)
    KEYBOARD_KEY_c0041=enter

    So, my theoretical at this point might be:

    evdev:input:b0005v0508p1980*
    KEYBOARD_KEY_c0028=enter

    The problem is I have a button labeled "OK", but there's no "OK" string in any of this output, soooo... Which keyboard key is it that I'm trying to map to the action "enter"? Sigh - so very close..

    When I run evtest to interactively watch my remote input, I keep getting this message and nothing is output:

    Code
    ***********************************************
     This device is grabbed by another process.
     No events are available to evtest while the
     other grab is active.
     In most cases, this is caused by an X driver,
     try VT-switching and re-run evtest again.
     Run the following command to see processes with
     an open fd on this device
    "fuser -v /dev/input/event3"
    ***********************************************

    ...So I have discovered the device, but now I can't see the key events to nail down the final mapping?

  • Code
    echo "evdev:input:b0005v0508p1980*" > /storage/.config/hwdb.d/99-UR02.hwdb
    echo " KEYBOARD_KEY_c0028=enter" >> /storage/.config/hwdb.d/99-UR02.hwdb
    reboot

    ^ That would be the correct format for a hwdb entry based on the info shared, but if the OK key is listed in evtest and can wake the RPi from screensaver I don't think that's the problem. One of the BT remotes I have needs a hwdb file creating to make the enter button work, and without the file is does absolutely nothing. No harm in experimenting tho. Worst case it does nothing and you can delete the file again afterwards.

  • Thanks, Chewitt!

    I've set up the file and tried a number of "c00$CODE" string variations - rebooting after each variation. So far, no luck..

    I had originally named the file "70-local-keyboard.hwdb", but as it's the ONLY init file in the hwdb.d directory, the file name hardly seems to matter.. (I updated it to your suggestion..)

    Code
    Livingroom:~ # cat /storage/.config/hwdb.d/99-UR02.hwdb
    evdev:input:b0005v0508p1980*
    KEYBOARD_KEY_c0096=enter
    Livingroom:~ #

    I've tried all the "enter" codes, and a few others including the c0041 quoted in the original article just for fun..

    I'll keep going down the list.. What heck - there are only a couple hundred possibilities, right? :D

    I'll report back if I figure out the right mix..

    Thanks for helping me at least figure out that I' on the right path here!

    Sincerely,

    -ET-

  • WOW - okay - this is SOLVED, (Happy dance! :thumbup: ) but only by VARIATIONS on all the help quoted above and so many repetitions my head is spinning. Let me, for the record, detail EXACTLY what worked here and how to repeat this with ANY blutooth remote.. Of course this is all based on my current revision of LE (12.0.0) and HW (RPi5). Your version/HW difference may be, well, different..

    Step One: REBOOT TO CLEAN SYSTEM STATE

    Code
    Livingroom:~ # reboot
    Livingroom:~ # Connection to livingroom closed by remote host.
    Connection to livingroom closed.
    $USERNAME@MacBook-Pro ~ %

    Step Two: LOGIN AS ROOT, STOP KODI (required to run evtest below!!)

    Code
    $USERNAME@MacBook-Pro ~ % ssh root@livingroom
    ##############################################
    #                 LibreELEC                  #
    #            https://libreelec.tv            #
    ##############################################
    LibreELEC (official): 12.0.0 (RPi5.aarch64)
    Livingroom:~ # systemctl stop kodi
    Livingroom:~ #

    Step Three: RUN journalctf -f (control -c when output stops!)

    Step Four: USE THE REMOTE - Just poke it a few times to make sure it's sending and LE is listening!

    Step Five: RUN /storage/.kodi/addons/virtual.system-tools/bin/evtest

    (example WITHOUT having used remote first!)

    Code
    Livingroom:~ # /storage/.kodi/addons/virtual.system-tools/bin/evtest
    No device specified, trying to scan all of /dev/input/event*
    Available devices:
    /dev/input/event0:    vc4-hdmi-0 HDMI Jack
    /dev/input/event1:    vc4-hdmi-1 HDMI Jack
    /dev/input/event2:    pwr_button
    Select the device event number [0-2]: ^C
    Livingroom:~ #

    (Example WITH "priming" the remote as you need to do to get this to work!!)

    Code
    Livingroom:~ # /storage/.kodi/addons/virtual.system-tools/bin/evtest
    No device specified, trying to scan all of /dev/input/event*
    Available devices:
    /dev/input/event0:    vc4-hdmi-0 HDMI Jack
    /dev/input/event1:    vc4-hdmi-1 HDMI Jack
    /dev/input/event2:    pwr_button
    /dev/input/event3:    UR02 Keyboard
    /dev/input/event4:    UR02 Mouse
    Select the device event number [0-4]:

    Choose the "Keyboard" device!!

    Code
    Select the device event number [0-4]: 3
    Input driver version is 1.0.1
    Input device ID: bus 0x5 vendor 0x508 product 0x1980 version 0x0
    Input device name: "UR02 Keyboard"
    --omitted output here (lots!)--
    Testing ... (interrupt to exit)

    Step Six: PRESS THE GOSH DARNED "OK" KEY on your remote that giving us all such a headache!! (just once, then ctl-c out)

    Code
    Testing ... (interrupt to exit)
    Event: time 1721363468.555115, type 20 (EV_REP), code 0 (REP_DELAY), value 500
    Event: time 1721363468.555115, type 4 (EV_MSC), code 4 (MSC_SCAN), value c0041
    Event: time 1721363468.555115, type 1 (EV_KEY), code 28 (KEY_ENTER), value 1
    Event: time 1721363468.555115, -------------- SYN_REPORT ------------
    Event: time 1721363468.704544, type 4 (EV_MSC), code 4 (MSC_SCAN), value c0041
    Event: time 1721363468.704544, type 1 (EV_KEY), code 28 (KEY_ENTER), value 0
    Event: time 1721363468.704544, -------------- SYN_REPORT ------------
    ^C
    Livingroom:~ #

    Step Seven: RUN cat /proc/bus/input/devices |grep Sysfs

    Code
    Livingroom:~ # cat /proc/bus/input/devices |grep Sysfs
    S: Sysfs=/devices/platform/soc/107c701400.hdmi/sound/card0/input0
    S: Sysfs=/devices/platform/soc/107c706400.hdmi/sound/card1/input1
    S: Sysfs=/devices/platform/pwr_button/input/input2
    S: Sysfs=/devices/virtual/misc/uhid/0005:0508:1980.0001/input/input3
    S: Sysfs=/devices/virtual/misc/uhid/0005:0508:1980.0001/input/input4
    Livingroom:~ #

    Step Eight: COALATE REQUIRED INFORMATION!!

    From /proc/bus/input/devices, you want the ling that looks like this:

    Code
    S: Sysfs=/devices/virtual/misc/uhid/0005:0508:1980.0001/input/input3

    You can ALSO grope around in the output of /storage/.kodi/addons/virtual.system-tools/bin/evtest for this data:

    Code
    Select the device event number [0-4]: 3
    Input driver version is 1.0.1
    Input device ID: bus 0x5 vendor 0x508 product 0x1980 version 0x0
    Input device name: "UR02 Keyboard"

    Which is translated in this line/format: Use 0005 as Bus, 0508 as Vendor and 1980* as Product:

    Code
    evdev:input:b0005v0508p1980*

    From the output of evtest, you want to use the "EV_MSC" and EV_SCAN output value, the LAST thing on the line:

    Code
    Event: time 1721363468.555115, type 4 (EV_MSC), code 4 (MSC_SCAN), value c0041

    Which is translated thus: (NOTE THE LEADING SPACE!!!) I had missed this and it forked me for a bit.. :cursing:

    Code
     KEYBOARD_KEY_c0041=enter

    Step Nine: Create a file: /storage/.config/hwdb.d/99-$SOMESTRING.hwdb
    Put these two lines you coalated from all this data into a file - essentially ANY file, but in startup.d name format in the /storage/.config/hwdb.d/ directory.
    Use anything you like for "$SOMESTRING" I used date related to my brand of remote. Format it as the example below.
    AGAIN, NOTE THE LEADING SPACE on the "KEYBOARD" line!! (the forum SW nicely trims this for us - so it was difficult to figure this little tidbit out!! It's CRITICAL!!) Credit Chewitt for plainly showing me, and me for blowing it at first.. :cursing:

    Code
    Livingroom:~ # cat /storage/.config/hwdb.d/99-UR02.hwdb
    evdev:input:b0005v0508p1980*
     KEYBOARD_KEY_c0041=enter
    Livingroom:~ #

    Step Ten: RUN /usr/bin/systemd-hwdb (Other posts list "udevadm hwdb --update", which works, but is depreciated..)

    Code
    Livingroom:~ # systemd-hwdb update
    Livingroom:~ # 

    Step Eleven: RUN /usr/bin/udevadm

    Code
    Livingroom:~ # udevadm trigger -s input
    Livingroom:~ # 

    Step Twelve: RESTART kodi!!

    Code
    Livingroom:~ # systemctl start kodi
    Livingroom:~ #

    Step Thirten: TEST!! Does it work - it did for me - it should for you! Congratulations!

    This was one of the most difficult things about kodi to figure out that I've ever encountered (Mostly because I can't read!! ^^ ) - and there are SO MANY FORUM ENTRIES ABOUT IT, but they seem a little scattered and none have the process listed from end to end, soo... Chewit detailed the leading space issue, but I missed it - dumb ass me. Hiassoft pointed me to a previous post that listed "udevadm hwdb --update" which is depreciated now and replace with systemd-hwdb.. Both work, but we should use the current stuff, right?

    Anyway, A SUPER SHOUTOUT to both ChewitT and HiassofT for their great assistance - could NOT have got it done without you!

    Hope this summary helps the next person in line that sees a deal in a cheap BT remote from AliExpress!!

    Time to watch a movie!!

    :D:P^^

  • Hi guys, I have the same problem, so I intend to follow the tutorial here.

    but when I get to the “evtest” step, I get an error.

    Bash
    ChipsTV:~ # /storage/.kodi/addons/virtual.system-tools/bin/evtest
    -sh: /storage/.kodi/addons/virtual.system-tools/bin/evtest: not found

    where can I get “evtest”?

  • sorry for my message above, I finally read it carefully and was able to solve this problem✨✨✨


    my remote is named ZTERCR21

    I have permission to open a pull request on github to add the ZTERCR21 remote in 70-local-keyboard.hwdb

    Many thanks to everyone involved in this forum🙏✨