Skip to content

Instantly share code, notes, and snippets.

@tvass

tvass/radio.py Secret

Created Oct 21, 2020
Embed
What would you like to do?
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
My version of the Internet Radio project.
"""
import serial
import subprocess, os
from time import sleep
print("starting radio ...")
my_env = os.environ
#my_env["MPD_HOST"] = "192.168.1.30"
ser = serial.Serial('/dev/ttyS0', 9600)
while True:
line = ser.readline().decode().strip('\r\n')
print(line)
if line.startswith('mpc next') or line.startswith('mpc prev'):
proc = subprocess.Popen(line, shell=True)
proc.wait()
proc = subprocess.Popen('mpc current -f %file% -h 192.168.1.30|cut -d"#" -f4', stdout=subprocess.PIPE, shell=True)
result = proc.communicate()[0]
ser.write("lcd %s".encode() % result)
if line.startswith('mpc vol'):
proc = subprocess.Popen(line, shell=True)
proc.wait()
proc = subprocess.Popen("mpc volume -h 192.168.1.30 |tr -dc '0-9'", stdout=subprocess.PIPE, shell=True)
volume = proc.communicate()[0]
ser.write("vol %s".encode() % volume)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment