OpenWrt/Music: Difference between revisions

From Wiki
No edit summary
Line 8: Line 8:
opkg update
opkg update
opkg install kmod-usb-audio kmod-usb-ohci kmod-usb-core kmod-sound-core
opkg install kmod-usb-audio kmod-usb-ohci kmod-usb-core kmod-sound-core
 
opkg install madplay mpc
opkg madplay mpc
opkg install snmpd
 
opkg install coreutils-stty
opkg snmpd
</pre>
</pre>
</blockquote>
</blockquote>


== create "madplay.sh" ==
== create files ==
<blockquote>
<blockquote>
<pre>
<pre>
Line 25: Line 24:
</blockquote>
</blockquote>


<blockquote>
<pre>
mkdir /etc/scripts
touch /etc/scripts/mpc.sh
chmod +x /etc/scripts/mpc.sh
vi /etc/scripts/mpc.sh
</pre>
</blockquote>
<blockquote>
<pre>
touch /etc/init.d/madplay
chmod +x /etc/init.d/madplay
vi /etc/init.d/madplay
</pre>
</blockquote>
<blockquote>
<pre>
mkdir /etc/scripts
touch /etc/scripts/serial.sh
chmod +x /etc/scripts/serial.sh
vi /etc/scripts/serial.sh
</pre>
</blockquote>
<blockquote>
<pre>
touch /etc/init.d/serial
chmod +x /etc/init.d/serial
vi /etc/init.d/serial
</pre>
</blockquote>
== file contents ==
::/etc/scripts/madplay.sh:
::/etc/scripts/madplay.sh:
<blockquote>
<blockquote>
Line 39: Line 74:
</blockquote>
</blockquote>


== create "mpc.sh" ==
::/etc/scripts/mpc_start.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>
Line 77: Line 102:
</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=192.168.111.10
vi /etc/init.d/madplay
 
mpc -h $IP stop
</pre>
</pre>
</blockquote>
</blockquote>
Line 127: Line 153:
}
}


</pre>
</blockquote>
== SNMP ==
<blockquote>
<pre>
opkg update
opkg install mini-snmpd
</pre>
</blockquote>
== Serial interface ==
<blockquote>
<pre>
mkdir /etc/scripts
touch /etc/scripts/serial.sh
chmod +x /etc/scripts/serial.sh
vi /etc/scripts/serial.sh
</pre>
</pre>
</blockquote>
</blockquote>
Line 157: Line 165:
trap 'kill $! ; exit 1' SIGINT
trap 'kill $! ; exit 1' SIGINT
port="/dev/tts/0"
port="/dev/tts/0"
stty $port 9600 -echo
stty -F $port 9600 -echo


echo "OpenWrt booted\n" > $port
echo "!C,booted*" > $port


while true
while true
Line 172: Line 180:
   echo "$inputline"
   echo "$inputline"
done  
done  
</pre>
</blockquote>
== create serial init.d script ==
<blockquote>
<pre>
touch /etc/init.d/serial
chmod +x /etc/init.d/serial
vi /etc/init.d/serial
</pre>
</pre>
</blockquote>
</blockquote>

Revision as of 10:36, 5 October 2012

OpenWrt music streaming

Streaming music via OpenWrt on 4MB flash router Since /etc is preserved during sysupgrades, we keep everything there.

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
touch /etc/scripts/madplay.sh
chmod +x /etc/scripts/madplay.sh
vi /etc/scripts/madplay.sh
mkdir /etc/scripts
touch /etc/scripts/mpc.sh
chmod +x /etc/scripts/mpc.sh
vi /etc/scripts/mpc.sh
touch /etc/init.d/madplay
chmod +x /etc/init.d/madplay
vi /etc/init.d/madplay
mkdir /etc/scripts
touch /etc/scripts/serial.sh
chmod +x /etc/scripts/serial.sh
vi /etc/scripts/serial.sh
touch /etc/init.d/serial
chmod +x /etc/init.d/serial
vi /etc/init.d/serial


file contents

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

while true
 do
 	sleep 2
 	wget -O - http://192.168.111.10:8000 | madplay -
 	sleep 18
 done
/etc/scripts/mpc_start.sh
#!/bin/sh
IP=192.168.111.10

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=192.168.111.10

mpc -h $IP stop
/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/scripts/serial.sh:
#! /bin/sh
#
#

trap 'kill $! ; exit 1' SIGINT
port="/dev/tts/0"
stty -F $port 9600 -echo

echo "!C,booted*" > $port

while true
do
   inputline=""
	
   until inputline=$(echo $inputline | grep -e "!A,")
   do
      inputline=$(head -n 1 < $port)
   done
   
   echo "$inputline"
done 
/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
}