Skip to content

Instantly share code, notes, and snippets.

@tvass

tvass/radio.py Secret

Created October 21, 2020 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvass/a9191149a69855f5f3c676af9135ee3a to your computer and use it in GitHub Desktop.
Save tvass/a9191149a69855f5f3c676af9135ee3a to your computer and use it in GitHub Desktop.
#!/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