Hi,
I was facing the similar challenge and the post above has inspired me to solve my problem. The goal was to turn on my AVR (ARCAM350) when RPi is playing musing and turn it off when there is no music. So I have created 3 files:
1) To control my Arcam AVR
- Code: Select all
#! /bin/sh
# avr300
ARCAM=/dev/ttyUSB0
case "$1" in
on)
stty 38400 < $ARCAM
echo -e "PC_*11\r" > $ARCAM
echo -e "PC_110\r" > $ARCAM
;;
off)
stty 38400 < $ARCAM
echo -e "PC_*10\r" > $ARCAM
;;
cmd)
if [ -n "$2" ]; then
stty 38400 < $ARCAM
echo -e "$2\r" > $ARCAM
else
echo "Usage: $0 $1 {command}"
fi
;;
*)
echo "Usage: $0 {on | off |cmd command}"
exit 1
;;
esac
exit 0
2) Is a Servicing monitoring soundcard (based on post above)
- Code: Select all
#! /bin/sh
# ctrlavr
TMPFILE=/tmp/test_sound.tmp
TURNOFFDELAY=300
TERNOFFPULL=10
TESTSOUNDPULL=1
COUNTOFSILENCE=0
soundTest()
{
cat /proc/asound/card?/pcm?p/sub?/hw_params | grep -v closed > "$TMPFILE"
FILESIZE=$(stat -c%s "$TMPFILE")
return $FILESIZE
}
#wait for playing
while sleep $TESTSOUNDPULL;
do
soundTest
if [ $? -ne 0 ]; then
#Playing turn on amp
echo "Playing audio ..."
avr300 on
COUNTOFSILENCE=0
#Wait for stop playing
soundTest
while [ $? -ne 0 ];
do
sleep $TERNOFFPULL
soundTest
done
echo "Sound of silence ..."
else
COUNTOFSILENCE=$(($TESTSOUNDPULL + $COUNTOFSILENCE))
if [ $COUNTOFSILENCE -gt $TURNOFFDELAY ]; then
COUNTOFSILENCE=0
echo "Turn off external AMP"
avr300 off
fi
fi
done
3) Is Service descriptor for ArchLinux to start service on boot
- Code: Select all
Description=Turns on/off the Arcam AVR300
Requires=
After=
[Service]
Type=simple
ExecStart=/usr/local/bin/ctrlavr
TimeoutSec=0
[Install]
WantedBy=multi-user.target
Script no. 1 & 2 are located in /usr/local/bin/ and needs to have execution priviledges.
File no. 3 is located in /usr/lib/systemd/system/ and needs to be enabled using systemctl enable command.
I am not a Linux geek, so please do not be cruel about judging my scripting skills
. Any comments are welcome and I hope you can find it useful to make your own RPI network audio player controlling your AVR.
Have a fun,
Szymon