OpenWrt/Music: Difference between revisions

From Wiki
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
== OpenWrt music streaming ==
== OpenWrt music streaming ==
Streaming music via OpenWrt on 4MB flash router
Streaming music via OpenWrt on 4MB flash router
Since /etc is preserved during sysupgrades, we keep everything there.


== Install packages ==
== Install packages ==
Line 7: Line 6:
<pre>
<pre>
opkg update
opkg update
opkg install kmod-usb-audio kmod-usb-ohci kmod-usb-core kmod-sound-core madplay
opkg install kmod-usb-audio kmod-usb-ohci kmod-usb-core kmod-sound-core
opkg install madplay mpc
opkg install snmpd
opkg install coreutils-stty
</pre>
</pre>
</blockquote>
</blockquote>


== create "madplay.sh" ==
== create files ==
<blockquote>
<blockquote>
<pre>
<pre>
mkdir /etc/scripts
mkdir /etc/scripts ; cd /etc/scripts
touch /etc/scripts/madplay.sh
touch madplay.sh ; chmod +x $_
chmod +x /etc/scripts/madplay.sh
touch mpc_alarm.sh ; chmod +x $_
vi /etc/scripts/madplay.sh
touch mpc_stop.sh ; chmod +x $_
touch serial.sh ; chmod +x $_
touch madplay_ip.conf ; touch mpc_ip.conf
</pre>
</pre>
</blockquote>
</blockquote>


<blockquote>
<pre>
cd /etc/init.d
touch madplay ; chmod +x $_
touch serial ; chmod +x $_
</pre>
</blockquote>
== file contents ==
::/etc/scripts/madplay.sh:
::/etc/scripts/madplay.sh:
<blockquote>
<blockquote>
Line 29: Line 42:
  do
  do
  sleep 2
  sleep 2
  wget -O - http://192.168.111.10:8000 | madplay -
  wget -O - `cat /etc/scripts/madplay_ip.conf` | madplay -
  sleep 18
  sleep 8
  done
  done
</pre>
</pre>
</blockquote>
</blockquote>


== create "mpc.sh" ==
::/etc/scripts/mpc_alarm.sh:
<blockquote>
<pre>
mkdir /etc/scripts
touch /etc/scripts/mpc.sh
chmod +x /etc/scripts/mpc.sh
vi /etc/scripts/mpc.sh
</pre>
</blockquote>
 
:: /etc/scripts/mpc.sh:
<blockquote>
<blockquote>
<pre>
<pre>
#!/bin/sh
#!/bin/sh
IP=192.168.111.10
IP=`cat /etc/scripts/mpc_ip.conf`


mpc -h $IP clear
mpc -h $IP clear
Line 73: Line 76:
</blockquote>
</blockquote>


== create madplay init.d script ==
::/etc/scripts/mpc_stop.sh:
<blockquote>
<blockquote>
<pre>
<pre>
touch /etc/init.d/madplay
#!/bin/sh
chmod +x /etc/init.d/madplay
IP=`cat /etc/scripts/mpc_ip.conf`
vi /etc/init.d/madplay.sh
 
mpc -h $IP stop
</pre>
</blockquote>
 
 
::/etc/scripts/serial.sh:
<blockquote>
<pre>
#! /bin/sh
#
port="/dev/ttyATH0"
stty -F $port 9600 -echo
 
echo "!C,booted*" > $port
 
while true
do
  serialinput=""
  until serialinput=$(echo $serialinput | egrep "!A,|!C,")        # egrep "|" = OR
  do
      serialinput=$(head -n 1 < $port)
  done
 
  echo "$serialinput"
 
  case "$serialinput" in
    "!C,AlarmStart*"  ) /etc/scripts/mpc_alarm.sh &;;
    "!C,AlarmStop*"  ) /etc/scripts/mpc_stop.sh &;;
  esac
 
done
 
</pre>
</pre>
</blockquote>
</blockquote>
Line 122: Line 158:
rm -f $PIDFILE
rm -f $PIDFILE
}
}
</pre>
</blockquote>
:: /etc/init.d/serial:
<blockquote>
<pre>
#!/bin/sh /etc/rc.common
# serial interface script
START=99
DAEMON=/etc/scripts/serial.sh
DAEMONNAME=serial
PIDFILE=/var/run/serial.pid
start() {
echo -n "starting: $DAEMONNAME"
if [ -f $PIDFILE ] ; then
  echo
  echo "$DAEMONNAME already running (PID=`cat $PIDFILE`)"
  exit
fi
touch $PIDFILE
start-stop-daemon -S -p $PIDFILE -m -b -x $DAEMON
echo "(PID=`cat $PIDFILE`)"
}
stop() {
if [ ! -f $PIDFILE ] ; then
  echo "$DAEMONNAME is not running"
  exit
fi
PID=`cat $PIDFILE`
echo "stopping: $DAEMONNAME(PID=$PID)"
kill -INT $PID
pkill -INT -P $PID
rm -f $PIDFILE
}
</pre>
</blockquote>
==  ==
<blockquote>
<pre>
</pre>
</blockquote>
==  ==
<blockquote>
<pre>


</pre>
</pre>
</blockquote>
</blockquote>

Latest revision as of 10:13, 8 November 2012

OpenWrt music streaming

Streaming music via OpenWrt on 4MB flash router

Install packages

opkg update
opkg install kmod-usb-audio kmod-usb-ohci kmod-usb-core kmod-sound-core
opkg install madplay mpc
opkg install snmpd
opkg install coreutils-stty

create files

mkdir /etc/scripts ; cd /etc/scripts
touch madplay.sh ; chmod +x $_
touch mpc_alarm.sh ; chmod +x $_
touch mpc_stop.sh ; chmod +x $_
touch serial.sh ; chmod +x $_
touch madplay_ip.conf ; touch mpc_ip.conf
cd /etc/init.d
touch madplay ; chmod +x $_
touch serial ; chmod +x $_

file contents

/etc/scripts/madplay.sh:
#! /bin/sh

while true
 do
 	sleep 2
 	wget -O - `cat /etc/scripts/madplay_ip.conf` | madplay -
 	sleep 8
 done
/etc/scripts/mpc_alarm.sh:
#!/bin/sh
IP=`cat /etc/scripts/mpc_ip.conf`

mpc -h $IP clear
mpc -h $IP repeat on
mpc -h $IP random off
mpc -h $IP single off
mpc -h $IP consume off
mpc -h $IP enable 2

mpc -h $IP load "Alarm Clock Intro"
mpc -h $IP shuffle
mpc -h $IP play

sleep 60

mpc -h $IP stop
mpc -h $IP clear
mpc -h $IP load "Alarm Clock"
mpc -h $IP random on
mpc -h $IP play

/etc/scripts/mpc_stop.sh:
#!/bin/sh
IP=`cat /etc/scripts/mpc_ip.conf`

mpc -h $IP stop


/etc/scripts/serial.sh:
#! /bin/sh
#
port="/dev/ttyATH0"
stty -F $port 9600 -echo

echo "!C,booted*" > $port

while true
do
   serialinput=""
	
   until serialinput=$(echo $serialinput | egrep "!A,|!C,")        # egrep "|" = OR
   do
      serialinput=$(head -n 1 < $port)
   done
   
   echo "$serialinput"

   case "$serialinput" in
     "!C,AlarmStart*"  ) /etc/scripts/mpc_alarm.sh &;;
     "!C,AlarmStop*"   ) /etc/scripts/mpc_stop.sh &;;
   esac 

done 

/etc/init.d/madplay:
#!/bin/sh /etc/rc.common
# madplay script

START=99

DAEMON=/etc/scripts/madplay.sh
DAEMONNAME=madplay
PIDFILE=/var/run/madplay.pid

start() {
	echo -n "starting: $DAEMONNAME" 

	if [ -f $PIDFILE ] ; then
	   echo
	   echo "$DAEMONNAME already running (PID=`cat $PIDFILE`)"
	   exit
	fi	

	touch $PIDFILE
	start-stop-daemon -S -p $PIDFILE -m -b -x $DAEMON
	echo "(PID=`cat $PIDFILE`)"
}

stop() {
	if [ ! -f $PIDFILE ] ; then
	   echo "$DAEMONNAME is not running"
	   exit
	fi

	PID=`cat $PIDFILE`
	echo "stopping: $DAEMONNAME(PID=$PID)"
		
	kill -INT $PID
	pkill -INT -P $PID

	rm -f $PIDFILE
}


/etc/init.d/serial:
#!/bin/sh /etc/rc.common
# serial interface script

START=99

DAEMON=/etc/scripts/serial.sh
DAEMONNAME=serial
PIDFILE=/var/run/serial.pid

start() {
	echo -n "starting: $DAEMONNAME" 

	if [ -f $PIDFILE ] ; then
	   echo
	   echo "$DAEMONNAME already running (PID=`cat $PIDFILE`)"
	   exit
	fi	

	touch $PIDFILE
	start-stop-daemon -S -p $PIDFILE -m -b -x $DAEMON
	echo "(PID=`cat $PIDFILE`)"
}

stop() {
	if [ ! -f $PIDFILE ] ; then
	   echo "$DAEMONNAME is not running"
	   exit
	fi

	PID=`cat $PIDFILE`
	echo "stopping: $DAEMONNAME(PID=$PID)"
		
	kill -INT $PID
	pkill -INT -P $PID

	rm -f $PIDFILE
}