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
- Enter your RPI4 via ssh and pair your remote with bluetoothctl (comes with Volumio)
- Copy file g20.py (below) to /home/volumio and give execution permission: chmod +x g20.py
- Under sudo create file /lib/systemd/system/g20.service (below)
- sudo systemctl enable g20
- 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