added volumio-control.py

This commit is contained in:
2024-08-20 12:36:25 +00:00
parent 1cfd18c8ca
commit 567fd9daf2
+65
View File
@@ -0,0 +1,65 @@
#####
# # enable ssh at http://volumio.local/dev
#
# # fix sources https://forums.raspberrypi.com/viewtopic.php?t=320294#p1918001
# sudo apt-get update
#
# sudo apt-get install python3-dev python3-rpi.gpio
# sudo apt-get install python3-pip
# pip3 install python-socketio==4.6.1 # https://community.volumio.com/t/cannot-connect-to-volumio-using-pythons-socketio-client/67479/2
# # https://python-socketio.readthedocs.io/en/v4/client.html#creating-a-client-instance
#####
import RPi.GPIO as GPIO
import socketio
GPIO.setmode(GPIO.BOARD)
sio = socketio.Client()
sio.connect('http://localhost:3000')
status = 'pause'
def button_pressed(channel):
if channel == 11:
print('next')
sio.emit('next')
elif channel == 13:
# print('state', status)
if status == 'play':
print('pause')
sio.emit('pause')
else:
print('play')
sio.emit('play')
elif channel == 15:
print('prev')
sio.emit('prev')
def setup_channel(channel):
try:
print("register %d" %channel)
GPIO.setup(channel, GPIO.IN, GPIO.PUD_UP)
GPIO.add_event_detect(channel, GPIO.FALLING, callback = button_pressed, bouncetime = 400)
print('success')
except (ValueError, RuntimeError) as e:
print('ERROR:', e)
for x in [11, 13, 15]:
setup_channel(x)
@sio.on('pushState')
def on_push_state(*args):
global status
status = args[0]['status']
print(status)
# get initial state
sio.emit('getState')
try:
while True : pass
except:
GPIO.cleanup()