Sunspot Home . . . . . . Joggler menu

Running CGI scripts from a web page to run C code, Sox, flite etc
-to first control the backlight and the Joggler i2c light sensor and (later) i2c external devices

In my (Debian)Slug and (Openwrt)Sweex and (Debian)Bifferboard I can run cgi scripts in /var/www/cgi-bin and have these run in turn bash scripts that can then run C code, sound players, text to speech etc.

On (Ubuntu)Joggler using lighttpd as downloaded I can run bash scripts and Blassic basic but NOT Flite, Sox, readlightsensor etc even though these run fine when I run the bash scripts that call them in a root SSH terminal.

The answer is to run lighttpd as root (just as in my other platforms)
BUT the Ubuntu lighttpd download refuses to do so!!
The fix is here

I have a set of scripts that use cgi files in /var/www/cgi-bin/scripts that allow a link on a web page to run Joggler programs.


 How the scripts work (current work backup - just a test to be modified later as needed)

The demo web page below is called after loading http://192.168.0.247/cgi-bin/scripts/scripts.cgi



using
-


/var/www/cgi-bin/scripts/scripts.cgi

#!/bin/sh

#Decode query string

IFS="&"
for QUERY_PARTS in $QUERY_STRING; do
QKEY="`echo $QUERY_PARTS | cut -d '=' -f 1`"
QVAL="`echo $QUERY_PARTS | cut -d '=' -f 2`"
eval "`httpd -d "$QKEY"`=\"`httpd -d "$QVAL"`\""
# remove next line for OpenWrt
eval "$QKEY=\"$QVAL\""
done

# when the page is first opened load the text from pg-default.sh
# this page is addressed like ->
# index.cgi?page=rs232send&string=HARRY
# so the values of both page and string are sent to this script
# thus if page=rs232send the script we run will be pg-rs232send.sh

# has the variable page been given a value?
if [ -e "pg-$page.sh" ]; then
inc="./pg-$page.sh"

# if not then show the default text
else
inc="./pg-default.sh"
page="default"
fi

echo "Content-type: text/html"
echo

#send first part of the html page
cat scripts.html
echo "<!-- Content goes here -->"
. $inc
echo "<!-- End of content -->"
echo "scripts.cgi now printing to the web page"
echo "<BR>Uptime: `cat /proc/uptime | cut -d ' ' -f 1` seconds.<br>"
# now finish the html
echo "<BR></body></html>"
#cat path_to/end.html <-use for a more complex end to the page


The top part of the page is built by
scripts.cgi from :-

/var/www/cgi-bin/scripts/scripts.html

<html>
<head>
<!HTTP/1.0 200>
<title>scripts</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFCC">

<font color="#009900" size="4" face="Arial, Helvetica, sans-serif"><strong>Joggler Control Scripts</strong></font></p>
<p><strong><font color="#FF0000" size="3" face="Arial, Helvetica, sans-serif"><HR>run a script </font></strong></p>

<font size="3" face="Arial, Helvetica, sans-serif"><a href="http:/cgi-bin/scripts/scripts.cgi?page=scripts&string=/var/www/cgi-bin/scripts/sound_test.sh">sound test </a></font> </font>

<BR><BR>

<font size="3" face="Arial, Helvetica, sans-serif"><a href="http:/cgi-bin/scripts/scripts.cgi?page=scripts&string=/var/www/cgi-bin/scripts/read_light_level.sh">read light level</a></font>
<BR><BR>

<font size="3" face="Arial, Helvetica, sans-serif"><a href="http:/cgi-bin/scripts/scripts.cgi?page=scripts&string=/var/www/cgi-bin/scripts/play_a_wav.sh">play wav with Sox</a></font>
<BR><BR>

<font size="3" face="Arial, Helvetica, sans-serif"><a href="http:/cgi-bin/scripts/scripts.cgi?page=scripts&string=/var/www/cgi-bin/scripts/screen_32.sh">bright screen</a></font>
- - - - -

<font size="3" face="Arial, Helvetica, sans-serif"><a href="http:/cgi-bin/scripts/scripts.cgi?page=scripts&string=/var/www/cgi-bin/scripts/screen_12.sh">dim screen</a></font>
- - - - -

<font size="3" face="Arial, Helvetica, sans-serif"><a href="http:/cgi-bin/scripts/scripts.cgi?page=scripts&string=/var/www/cgi-bin/scripts/screen_0.sh">dark screen</a></font>
<BR><BR>

the clicked link makes page = scripts and so the file pg-scripts.sh runs

/var/www/cgi-bin/scripts/pg-scripts.sh

#!/bin/sh

# send all this to the web page

echo '<font color=blue size=3 face=Arial>'
echo 'now running the script '
echo '</font>'

echo '<font color=red size=3 face=Arial>'
echo $string
echo '</font><BR>'

# run the script with the name string

$string



pg-scripts.sh runs this if the clicked link made string=/var/www/cgi-bin/scripts/sound_test.sh

/var/www/cgi-bin/scripts/sound_test.sh

#!/bin/bash

echo "<BR> sound test now <BR>"

flite -t ' eff lite is speaking '

date



pg-scripts.sh runs this if the clicked link made string=/var/www/cgi-bin/scripts/read_light_level.sh

/var/www/cgi-bin/scripts/read_light_level.sh

#!/bin/bash

echo "<BR><BR>Joggler light sensor value = "

# dump the first reading - seems to be in memory from last time light level was read
readlightsensor >> /dev/null 2>&1

# now write the light reading to the web page
readlightsensor

echo "<BR><BR>"

flite -t 'the light level is'
flite -t `readlightsensor`
date

pg-scripts.sh runs this if the clicked link made string=/var/www/cgi-bin/scripts/play_a_wav.sh

/var/www/cgi-bin/scripts/play_a_wav.sh

#!/bin/bash

play /home/graham/sounds/online.wav

echo "<BR><BR>"

date

pg-scripts.sh runs this if the clicked link made string=/var/www/cgi-bin/scripts/screen_32.sh

/var/www/cgi-bin/scripts/screen_32.sh

#!/bin/bash

echo -n 32 > /sys/class/backlight/openframe-bl/brightness

echo "<BR>Screen brightness is now 32 <BR><BR>"

date

 

Then scripts.cgi closes the html to finish the page.

§§§§§§§§§§§§§§§§§§§§§§§§§§§

The default below is used when http://192.168.0.247/cgi-bin/scripts/scripts.cgi is first called by the browser

/var/www/cgi-bin/scripts/default.sh

#!/bin/sh

#Generate the message that is first seen

echo "<BR><font color=red size=3 face=Arial>"
echo "this message comes up when the main script is first used<BR>"
echo "normally says - - PLEASE CLICK ON A LINK ABOVE<BR>"
echo "</font>"

 

Remove the scroll bar in the Joggler Firefox display
My home page is a table matrix of 11 x 7 icons that are 60 x 60 pixels each (easy to click on with a finger tip).
There are also some Google Gadgets (weather, birthdays, clock) and the BBC iPlayer gadget.
To save precious screen area I wanted to remove the scroll bar on the right of the Firefox screen when in full screen mode.
Method
Install Stylish as a Firefox add-on.

By following these instruction I added a script to kill the scroll bar for the home page URL only
(as displayed in the Joggler - remote users still see the scroll bar)
The script to add is

no_scroll

@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);

scrollbar {visibility:collapse !important; }

 

 

 

Notes for future use
Sound volume control
The sound volume van be controlled from the command line
(perhaps in a script controlled by a web page) to any percentage of full on with, for example
amixer -c 0 -- sset Master playback 90%

Sunspot Home. . . . . Joggler menu