Added support of bluetooth remote G20BTS PRO to my Volumio on RPI4

Added support for exellent bluetooth remote G20BTS PRO (available on Aliexpress) to my RPI4 based Volumio. Now both playing commands and gyro mouse on screen with touchscreen plugin work perfectly

Here are steps

  1. Enter your RPI4 via ssh and pair your remote with bluetoothctl (comes with Volumio)
  2. Copy file g20.py (below) to /home/volumio and give execution permission: chmod +x g20.py
  3. Under sudo create file /lib/systemd/system/g20.service (below)
  4. sudo systemctl enable g20
  5. sudo systemctl start g20

Enjoy
Service will automatically be started on Volumio startup

File g20.py:

#!/usr/bin/python3

import struct
import requests
import time

URL='http://localhost:3000/api/v1/commands/?cmd='

dev_list_filename = '/proc/bus/input/devices'

while True:
    dev_list_file = open(dev_list_filename, 'r')

    dev_found = False
    infile_path = "/dev/input/"
    for line in dev_list_file:
        if '=' in line:
            tokens = line.split('=')
            if  'G20BTS PRO Consumer Control' in tokens[1]:
                dev_found = True
            if dev_found and 'Handlers' in tokens[0]:
                tokens = tokens[1].split(' ')
                infile_path = infile_path + tokens[1]
                break

    dev_list_file.close()
    if dev_found:
        EVENT_SIZE = struct.calcsize("llHHIllHHIllHHI")
        file = open(infile_path, "rb")
        event = file.read(EVENT_SIZE)
        pressed = -1
        while event:
            (tv_sec1, tv_usec1, type1, code1, value1, tv_sec2, tv_usec2, type2, code2, value2, tv_sec2, tv_usec3, type3, code3, value3) = struct.unpack("llHHIllHHIllHHI", event)
            if pressed == -1:
                pressed = value1

                url = ''

                if value1 == 786666:
                    url=URL + 'volume&volume=minus'
                elif value1 == 786665:
                    url=URL + 'volume&volume=plus'
                elif value1 == 786637:
                    url = URL + 'toggle'
                elif value1 == 786658:
                    url = URL + 'volume&volume=toggle'
                elif value1 == 786614:
                    url = URL + 'prev'
                elif value1 == 786613:
                    url = URL + 'next'
                if len(url) > 0:
                    try:
                        requests.get(url=url, timeout=0.000000001)
                    except requests.exceptions.ReadTimeout:
                        pass
            elif pressed == value1:
                pressed = -1
            event = file.read(EVENT_SIZE)
    else:
        time.sleep(1)

File g20.service:

[Unit]
Description = G20BT remote support

[Service]
ExecStart=/home/volumio/g20.py
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=G20
User=volumio
Group=volumio
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

1 Like

Thanks for sharing!

Just a a precaution.
This script might break the functionality of peppy_meter, due to the Python while loop.
If people want to use this with Peppy_meter, convert the loop to a bash script that calls this python script.

Thank you for valuable remark. I installed PeppyAlsa+PeppyMeter and saw a problem. When i created a very simple bash file:
#!/bin/bash
/home/volumio/g20.py

gave execution permission and wrote it’s name to g20.service, problem disappeared and both remote and PepperMeter work perfectly

I believe that in this way it is possible to use almost all kinds of both bluetooth and usb dongle based remotes (the only fix is proper vendor name and key codes)

1 Like

Yeah, I did test your script with:

Only part I needed to adapt was indeed the “Name”, key codes and infile_path = infile_path + tokens[2]
(depending on the location of value in ‘Handlers’)
But this depends on the type of BT remote.

So in short, a very usefull contribution :smile: