Difference between revisions of "Remote controlling via CGI Scripts"
(Add another simple shoutcast stream example) |
(call out that this doesn't work on Chumby8 (afaict)) |
||
(One intermediate revision by the same user not shown) | |||
Line 63: | Line 63: | ||
echo "" | echo "" | ||
echo "Now playing KEXP 128k" | echo "Now playing KEXP 128k" | ||
+ | </PRE> | ||
+ | |||
+ | ==multiple streams from one file== | ||
+ | Straightforward example with querystring argument to choose from a variety of streams (or stop the player). Fill in with streams / stream names as you see fit: | ||
+ | <PRE> | ||
+ | #!/bin/sh | ||
+ | echo "HTTP/1.1 200 ok" | ||
+ | echo "Content-type: text/html" | ||
+ | echo "" | ||
+ | if [ x"${QUERY_STRING}" = xkexp ]; then | ||
+ | echo "<event type=\"UserPlayer\" value=\"play\" comment=\"http://kexp-mp3-2.cac.washington.edu:8000/\"/>" > /tmp/flashplayer.event | ||
+ | elif [ x"${QUERY_STRING}" = xkuow ]; then | ||
+ | echo "<event type=\"UserPlayer\" value=\"play\" comment=\"http://128.208.34.80:8002/\"/>" > /tmp/flashplayer.event | ||
+ | elif [ x"${QUERY_STRING}" = xstop ]; then | ||
+ | echo "<event type=\"MusicPlayer\" value=\"stop\"/>" > /tmp/flashplayer.event | ||
+ | elif [ x"${QUERY_STRING}" = xindiepop ]; then | ||
+ | echo "<event type=\"UserPlayer\" value=\"play\" comment=\"http://ice.somafm.com/indiepop\"/>" > /tmp/flashplayer.event | ||
+ | elif [ x"${QUERY_STRING}" = xdoomed ]; then | ||
+ | echo "<event type=\"UserPlayer\" value=\"play\" comment=\"http://ice.somafm.com/doomed\"/>" > /tmp/flashplayer.event | ||
+ | elif [ x"${QUERY_STRING}" = xgroovesalad ]; then | ||
+ | echo "<event type=\"UserPlayer\" value=\"play\" comment=\"http://ice.somafm.com/groovesalad\"/>" > /tmp/flashplayer.event | ||
+ | else | ||
+ | echo "I don't know the $QUERY_STRING stream - try one of: kexp, kuow, indiepop, doomed, groovesalad, or stop" | ||
+ | fi | ||
+ | chumbyflashplayer.x -F1 > /dev/null 2>&1 | ||
+ | echo "" | ||
+ | echo "" | ||
+ | echo "Now playing ${QUERY_STRING}" | ||
</PRE> | </PRE> | ||
=Dimming the display= | =Dimming the display= | ||
+ | '''Note:''' This does not seem to work on a chumby8. | ||
+ | |||
<code>/proc/sys/sense1/dimlevel</code> can have different values: 0 is normal, 1 is dimmed, 2 is off. According to [http://wiki.chumby.com/mediawiki/index.php/Chumby_device_settings_information_on_/proc#.2Fproc.2Fsys.2Fsense1.2Fdimlevel], the display can't go from off to dimmed, so when going to the dimmed level, we just always switch to the normal level first and wait for a second. | <code>/proc/sys/sense1/dimlevel</code> can have different values: 0 is normal, 1 is dimmed, 2 is off. According to [http://wiki.chumby.com/mediawiki/index.php/Chumby_device_settings_information_on_/proc#.2Fproc.2Fsys.2Fsense1.2Fdimlevel], the display can't go from off to dimmed, so when going to the dimmed level, we just always switch to the normal level first and wait for a second. | ||
==dimmed== | ==dimmed== |
Latest revision as of 19:37, 18 February 2012
Contents
Basic Concept
I love my chumby, especially to listen to internet radio streams. But I hate to manipulate the device "by hand" to change a station or turn down the volume. Here are some simple cgi scripts to remote control your chumby. Basically, we're manipulating the control panel as described here via some cgi-scripts: Built-in webserver. Alternatively, we can manipulate /proc
or could call existing shell scripts.
Put the scripts in /psp/cgi-bin and access them via the built-in web server:
http://<ip.of.your.chumby>/cgi-bin/custom/<name.of.your.script>
Sound
Setting the volume
#!/bin/sh # /psp/cgi-bin/setvol # needs volume as parameter between 0 and 100 # e.g. http://<ip.of.you.chumby/cgi-bin/custom/setvol?30 # echo "HTTP/1.1 200 ok" echo "Content-type: text/html" echo "<event type=\"MusicPlayer\" value=\"setVolume\" comment=\"${QUERY_STRING}\"/>" > /tmp/flashplayer.event echo "" chumbyflashplayer.x -F1 > /dev/null 2>&1 echo "Volume set to ${QUERY_STRING}"
NB: Make sure you escape any quotation marks when echoing them in your script.
Muting
#!/bin/sh echo "HTTP/1.1 200 ok" echo "Content-type: text/html" echo "<event type=\"MusicPlayer\" value=\"setMute\" comment=\"on\"/>" > /tmp/flashplayer.event chumbyflashplayer.x -F1
Unmute with comment="off"
soma.fm
quick and dirty - just give it the name of your stream (groovesalad|secretagent|lush|digitalis|beatblender|...) as a parameter
#!/bin/sh echo "HTTP/1.1 200 ok" echo "Content-type: text/html" echo "" wget -c http://somafm.com/startstream=fw/${QUERY_STRING}.pls -O /tmp/${QUERY_STRING}.pls MYFILE=`grep File1= /tmp/${QUERY_STRING}.pls | cut -d "=" -f2` echo "<event type=\"UserPlayer\" value=\"play\" comment=\"${MYFILE}\"/>" > /tmp/flashplayer.event chumbyflashplayer.x -F1 > /dev/null 2>&1 echo "" echo "" echo "Now playing ${MYFILE}" rm /tmp/${QUERY_STRING}.pls
shoutcast stream
Simple example to start a specific shoutcast stream:
#!/bin/sh echo "HTTP/1.1 200 ok" echo "Content-type: text/html" echo "" echo "<event type=\"UserPlayer\" value=\"play\" comment=\"http://kexp-mp3-2.cac.washington.edu:8000/\"/>" > /tmp/flashplayer.event chumbyflashplayer.x -F1 > /dev/null 2>&1 echo "" echo "" echo "Now playing KEXP 128k"
multiple streams from one file
Straightforward example with querystring argument to choose from a variety of streams (or stop the player). Fill in with streams / stream names as you see fit:
#!/bin/sh echo "HTTP/1.1 200 ok" echo "Content-type: text/html" echo "" if [ x"${QUERY_STRING}" = xkexp ]; then echo "<event type=\"UserPlayer\" value=\"play\" comment=\"http://kexp-mp3-2.cac.washington.edu:8000/\"/>" > /tmp/flashplayer.event elif [ x"${QUERY_STRING}" = xkuow ]; then echo "<event type=\"UserPlayer\" value=\"play\" comment=\"http://128.208.34.80:8002/\"/>" > /tmp/flashplayer.event elif [ x"${QUERY_STRING}" = xstop ]; then echo "<event type=\"MusicPlayer\" value=\"stop\"/>" > /tmp/flashplayer.event elif [ x"${QUERY_STRING}" = xindiepop ]; then echo "<event type=\"UserPlayer\" value=\"play\" comment=\"http://ice.somafm.com/indiepop\"/>" > /tmp/flashplayer.event elif [ x"${QUERY_STRING}" = xdoomed ]; then echo "<event type=\"UserPlayer\" value=\"play\" comment=\"http://ice.somafm.com/doomed\"/>" > /tmp/flashplayer.event elif [ x"${QUERY_STRING}" = xgroovesalad ]; then echo "<event type=\"UserPlayer\" value=\"play\" comment=\"http://ice.somafm.com/groovesalad\"/>" > /tmp/flashplayer.event else echo "I don't know the $QUERY_STRING stream - try one of: kexp, kuow, indiepop, doomed, groovesalad, or stop" fi chumbyflashplayer.x -F1 > /dev/null 2>&1 echo "" echo "" echo "Now playing ${QUERY_STRING}"
Dimming the display
Note: This does not seem to work on a chumby8.
/proc/sys/sense1/dimlevel
can have different values: 0 is normal, 1 is dimmed, 2 is off. According to [1], the display can't go from off to dimmed, so when going to the dimmed level, we just always switch to the normal level first and wait for a second.
dimmed
#!/bin/sh echo "HTTP/1.1 200 ok" echo "Content-type: text/html" echo "" echo 0 > /proc/sys/sense1/dimlevel sleep 1 echo 1 > /proc/sys/sense1/dimlevel
off
#!/bin/sh echo "HTTP/1.1 200 ok" echo "Content-type: text/html" echo "" echo 2 > /proc/sys/sense1/dimlevel
Change the widget
use nextWidget
or prevWidget
as a value
#!/bin/sh echo "HTTP/1.1 200 ok" echo "Content-type: text/html" echo "" echo "<event type=\"WidgetPlayer\" value=\"nextWidget\" comment=\"\"/>" > /tmp/flashplayer.event chumbyflashplayer.x -F1 > /dev/null 2>&1
General interface
Once some of the above scripts are in place, you can create a file named "index" in the same directory, make it executable, and put these contents into that file and you'll have a small remote control for your chumby to control from a phone, laptop, or other device on your network. In this example, I have three chumbies, each with copies of these scripts in cgi-bin. The link at the top lets me change between the three. I also have a couple links to start some specific streaming radio stations (player_kexp and player_kuow).
#!/bin/sh echo "HTTP/1.1 200 ok" echo "Content-type: text/html" echo "" echo "<body style='background-color:666666; color:white'>" echo "<center>" echo "<h1>Chumby <a href='http://192.168.1.122/cgi-bin/custom/index'>Classic</a>, <a href='http://192.168.1.123/cgi-bin/custom/index'>Black8</a>, <a href='http://192.168.1.124/cgi-bin/custom/index'>Red8</a></h1>" echo "volume: <a href='player_setvol?20'>20</a>, <a href='player_setvol?40'>40</a>, <a href='player_setvol?60'>60</a>, <a href='player_setvol?80'>80</a>, <a href='player_setvol?100'>100</a><br>" echo "mute: <a href='player_setmute?on'>on</a>, <a href='player_setmute?off'>off</a><br>" echo "play: <a href='player_kexp'>kexp</a>, <a href='player_kuow'>kuow</a>, <a href='player_stop'>stop</a><br>" echo "display: <a href='display_off'>off</a>, <a href='display_dim'>dimmed</a>, <a href='display_normal'>normal</a>" echo "</center>" echo "</body>" echo ""