Sunspot Home - - - - - Joggler menu

Experimenting with the Joggler O2 native OS
telnet . ssh . scp . web server . Opera . Blassic basic . i2c
Run cgi scripts from web pages . Radio alarm . BBC live . Make it talk - flite .
Run scripts by pressing icons . Python

Objective
See if I can run a webserver that can run cgi scripts and run Bash, C and Blassic basic programs that can drive the i2c bus etc and display results on a web page. Also have these programs controlled by links on the served web page.
There might then be no need for a hub and external USB stick and I can use the O2 GUI that is very user friendly

1) Enable Telnet
Following the Wiki I put these files onto a FAT USB stick and booted the Joggler with the stick plugged in.
then -
telnet 192.168.0.61 (my LAN address for the 02 Joggler )
and then type
letmein

2) Enable SSH
In the Wiki Method 1 failed but Method 2 worked
In the Telnet session I pasted in these magic lines -

nvram -w net.login=YES
touch /etc/shadow
ln -s /openpeak/tango/common_libs/libgssapi_krb5.so.2 /lib/libgssapi_krb5.so.2
mkdir /var/run/sshd
cp -p /etc/ssh/sshd_config /etc/ssh/sshd_config.original
sed -i "s/UsePAM\ yes/\#UsePAM \yes/g" /etc/ssh/sshd_config
echo "letmeinssh:\$1\$ZiLC0meg\$e55qljsb4ssEKY3dQMsxP1:0:0:root:/:/bin/sh" >> /etc/passwd
/usr/sbin/sshd &
cp -p /etc/init.d/boot.d/S69boot.sshd /root/S69boot.sshd.original
sed -i "s/OFF in/\ in/g" /etc/init.d/boot.d/S69boot.sshd
sed -i "s/log_daemon_msg/\#\ log_daemon_msg/g" /etc/init.d/boot.d/S69boot.sshd
sync
sync

In my Mac terminal I typed
ssh letmeinssh@192.168.0.61
and gave the password joggler1234


3) Enable SCP
I did not know that SCP enables FTP file transfer
(I normally load vsftpd but there is no apt-get in the native O2 OS)
The Wiki again says how

In the SSH session I typed in -

cd /tmp
wget http://london.mnetcs.com/joggler/installSCP.sh
tr -d \\r < installSCP.sh > installSCP.unix.sh
chmod +x installSCP.unix.sh
./installSCP.unix.sh
rm installSCP.unix.sh
rm installSCP.sh

Then using Cyberduck ftp client on the Mac I ran a secure ftp session
login as letmein
password joggler1234

My backup of the key files is here

I can now edit Joggler files on the Mac using a decent context coloured text editor (TextWrangler) instead of the painful vi

4) Setup a web server
I normally use lighthtpd but see no way to load it - but the Wiki shows that httpd is part of an extended busybox file

The Joggler has /bin/busybox (339.9 KB) - I replaced this with busybox-1.6 (695.2 KB)
renamed to busybox
To do that I copied it to a new folder /home/graham then did
mv /home/graham/
busybox /bin/busybox
(I was not able to replace it by ftp directly to the bin folder)
The new Busybox gives the httpd webserver and also gives me cut that I need for scripting.

But you need to add a link for each new function
cd /bin
ln -s /bin/busybox cut
ln -s /bin/busybox httpd
ln -s /bin/busybox killall

just type busybox to see all the new functions - each one you want needs a symlink

/home/graham/httpd.conf is -

#!/bin/sh
H:/var/www
*.script:/bin/sh
*.bas:/usr/sbin/blassic
I:index.html
# end of file

You need to launch this at boot time with a script in
/etc/init.d/boot.d
I just added the command to
/etc/init.d/boot.dS99boot.hacks

that was created by the telnet hack - the top of that file looks like -

#!/bin/sh
starthacks()
{
# enable telnet
/usr/sbin/telnetd
# add your hacks here :)
httpd -c /home/graham/httpd.conf
} etc etc

Create a directory
/var/www
and add
index/html
like -

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Joggler 192.168.0.12</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#99ccff">
<p align="center"><font size="6" face="Arial, Helvetica, sans-serif">Welcome to Joggler 192.168.0.12<BR> native O2 OS</font><br>
</p>
</body>
</html>

5) Install Opera Browser
1. Download the opera application (or my backup here) - unzip it all and copy it to a memory stick.

Or ftp it to the /media folder and do
tar -zxvf operamobile.tar.gz

2. Download the icon (or my backup here) and put it in the /media/operamobile directory and rename it icon.swf

3. Modify the file "start "in the operamobile directory
"operamobile/start"
- add the following extra line shown in red:

#!/bin/sh
unset SDL_WINDOWID
export LD_LIBRARY_PATH=/media/operamobile/common-lib:/media/operamobile
export KMP_DUPLICATE_LIB_OK=TRUE
export DISPLAY=:0.0
export SDL_AUDIODRIVER=alsa
/media/operamobile/operamobile -geometry 800x480 -mem 256M

4 . Add the following line to the file: /openpeak/gui/o2-applications.xml

<app static="1" id="operamobile" loc="/media/operamobile/" ext="1" standalone="0" app="/media/operamobile/start" title="Opera Mobile" icon="icon.swf"/>

5. Add the following line to the file: /openpeak/gui/config.xml
<external_process>./apps/externalprocess/main.swf</external_process>
- add this to the next line down after the entry <languages>
and before </config>

6. Reboot and start Opera from the "O" icon

8. It is possible to reposition the buttons by pushing and holding the icon you wish to move, and you can move from screen to screen too.

Thanks to Dave and -

http://forums.thedigitalfix.co.uk/forums/showthread.php?p=9154268
http://www.joggler.info/forum/viewtopic.php?f=33&t=867&sid=10ba4738fad9394b3d6d77ece9cf430b
http://www.cs.colostate.edu/helpdocs/vi.html

Note - type about:config into the address bar to get loads of options

9) Make the Opera default font size much more readable on Joggler
add to media/operamobile/opera.ini

Code:
[Fonts]
Form.Button=25,3,0,0,0,0,Tahoma
Form.Input=25,3,0,0,0,0,Tahoma
Form.Text=24,3,0,0,0,0,Courier New
H1=40,5,0,0,0,0,Tahoma
H2=34,5,0,0,0,0,Tahoma
H3=30,5,0,0,0,0,Tahoma
H4=26,5,0,0,0,0,Tahoma
H5=22,5,0,0,0,0,Tahoma
H6=20,5,0,0,0,0,Tahoma
Normal=25,3,0,0,0,0,Tahoma
PRE=23,3,0,0,0,0,Courier New

Thanks to this post

6) Run the Blassic basic programing language for use with cgi scripting etc (very easy to learn!)

Add Blassic to /usr/sbin see http://www.sunspot.co.uk/Projects/sweexproject.htm menu item 12

7) Run the i2c bus control tools - I took these from the Ubuntu stick that I use with Jogglers - put them into /usr/sbin
i2cdetect - - i2cget - - i2cset

 





9) Run cgi scripts from web pages
- control an i2c bus on the Joggler from any browser
- read temperatures/ voltages / switch relays etc ALL WITH THE NATIVE O2 software!

In /var create folders /www/cgi-bin/
I tested cgi scripting by using the i2c bus to read what seems to be a thermometer reading the cpu temperature at 0x4c

# cd /
# i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n]
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- 18 -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- 34 -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- 4c -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- 69 -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
#

I use a Blassic basic program to read from SE95 thermometers and whatever is at 0x4c seems to respond to it!

#!/usr/sbin/blassic
' use i2cset and i2cget to read a SE95 13 bit i2c thermometer
' with all 3 address lines tied to 5 volts the address is 0x4f (decimal 79)
' available decimal addresses are 72 73 74 75 76 77 78 79
'/home/graham/SE95_i2ctools_read_once.bas 76
<--(for 0x4c)

address$ = PROGRAMARG$(1)

'write a 0 to the 0 register
SHELL "i2cset -y 0 "+address$+" 0x00 0x00 b > /dev/null 2>&1"

SHELL "i2cget -y 0 "+address$+" 0x00 w > /var/www/ramdisk/lm75_1.txt"
OPEN "/var/www/ramdisk/lm75_1.txt" FOR INPUT AS #1:INPUT #1,temp$:CLOSE #1

'get the two hex bytes from the stored text string
HI$ = RIGHT$(temp$,2) : LO$ = MID$(temp$,3,2)

'get the decimal value of the hex numbers
HI_dec = VAL("&h"+ HI$) : LO_dec = VAL("&h"+ LO$)

sign = 1
' if bit 7 of the HI byte is 1 then the temperature is negative
' convert twos complement to decimal (invert all bits and add 1 to the low byte)
IF HI_dec >= 128 THEN HI_dec = HI_dec XOR 255 :LO_dec = (LO_dec XOR 255) +1: sign = -1

temp_all = (HI_dec + LO_dec/256)
temp_1_dec = ROUND(temp_all,1)
IF temp_1_dec = 0 THEN sign = 1
temp_1_dec = sign * temp_1_dec
PRINT temp_1_dec

SYSTEM


This uses a ramdisk to transfer data from bash scripts to and from Blassic basic
Create it at boot up in
/etc/init.d/boot.d


#!/bin/sh

# launch the web server at boot time
cd /media/build
./busybox-1.6 httpd -c httpd.conf

# build a ramdisk for Blassic data transfers
cd /
mkdir /var/www/ramdisk
mount -o size=2M -t tmpfs tmpfs /var/www/ramdisk

/var/www/index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>O2 Native Web Pages</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#99ccff">
<p align="left"><font color="#FF0000" size="5" face="Arial, Helvetica, sans-serif">Welcome
to the O2 native Joggler website</font><font size="5" face="Arial, Helvetica, sans-serif"><BR>
<BR>
<font size="4">(view at 192.168.0.12 </font></font><font size="4" face="Arial, Helvetica, sans-serif">from the LAN,</font></p>
<p align="left"><font size="4" face="Arial, Helvetica, sans-serif">127.0.0.1 from the Opera browser in this Joggler)</font></p>
<p align="left"><font size="4" face="Arial, Helvetica, sans-serif">running on busybox httpd from /media/build/busybox-1.6 </font></p>
<p align="left"><br>
<font size="3" face="Arial, Helvetica, sans-serif">1) <a href="cgi-bin/i2c_test.cgi"><font size="7">CGI i2c test</font></a> - see the CPU core temperature</font></p>
</body>
</html>

/var/www/i2ctest.cgi

#!/bin/sh
# derived from index.cgi

#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"`\""
eval "$QKEY=\"$QVAL\""
done

# when the page is first opened load the text from pg-default.sh
# the pg-xxxxx.sh page is addressed like ->
# index.cgi?page=xxxxxsend&string=HARRY
# or even index.cgi?page=xxxxxsend&string1=HARRY&string2=MARY
# (and as many strings as you want)
# 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 start.html which is the first part of the html page
cat i2c_test.html
echo "<!-- Content goes here -->"
. $inc
echo "<!-- End of content -->"
echo "<BR>"
echo "Joggler uptime: `cat /proc/uptime | cut -d ' ' -f 1` seconds.<br>"
# now finish the html
echo "<BR></body></html>"

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

<html>
<head>

<title>run i2c test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body bgcolor="#FFFFCC">

<p><font color="#FF0000" size="4" face="Arial, Helvetica, sans-serif"><strong>i2c
tests <BR>
(testing CGI scripting on the native O2 software)</strong></font></p>
<p>
<font size="6" face="Arial, Helvetica, sans-serif"><a href="i2c_test.cgi?page=i2ctest">Read the CPU (?) temperature</a></font></p>

/var/www/cgi-bin/pg_default.sh

#!/bin/sh

#Generate the message that is first seen

echo "<BR><font color=red size=3 face=Arial>"
echo "Welcome! Please click on a link above<BR>"
echo "</font>"

/var/www/cgi-bin/pg_i2c_test.sh

#!/bin/sh
#pg-i2c_test.sh

echo "<font color=red size=6 face=Arial >"
echo`date`
echo "</font>"
echo " <BR><BR><font color=blue size=5 face=Arial >"

echo "<HR>The CPU core temperature is "
#run the i2c thermometer reader program

/home/graham/SE95_i2ctools_read_once.bas 76

echo " degrees <BR><HR></font>"

# note for reference- this method works as well as using the raw program name
#echo `PCF8591_addr_line_V 76 3 123`

 

10) Make the alarm clock sound be a live MP3 radio stream

My summary of http://www.joggler.info/forum/viewtopic.php?f=24&t=556

NB the method below is needed for software SWR 26635.S3

If your taste is different choose a stream from other stations listed here http://www.radiofeeds.co.uk/mp3.asp
I got the URL by opening the stream in iTunes and then doing a "show info"

Create a text file - /openpeak/gui/apps/o2_alarm_clock/ClassicFM.M3U containing
http://media-ice.musicradio.com:80/ClassicFMMP3

Create a text file - /openpeak/gui/apps/o2_alarm_clock/bbcWorld.M3U containing
http://vprbbc.streamguys.net:80/vprbbc24.mp3

Change /openpeak/tango/o2_alarmclock.ini to

[config]
ring_path1=http://vprbbc.streamguys.net:80/vprbbc24.mp3
ring_path2=http://media-ice.musicradio.com:80/ClassicFMMP3

volume1=4
volume2=4
ring_name1=BBC World
ring_name2=Classic FM

/media/app-cfg/o2_alarm_clock/tones.xml is -

<tones>
<tone Name="BBC World" Path="bbcWorld.M3U"/>
<tone Name="Classic FM" Path="ClassicFM.M3U"/>
<tone Name="Alarm 3" Path="alarm3.mp3"/>
<tone Name="Siren 1" Path="siren1.mp3"/>
<tone Name="Siren 2" Path="siren2.mp3"/>
<tone Name="Siren 3" Path="siren3.mp3"/>
<tone Name="Siren 4" Path="siren4.mp3"/>
</tones>

Alarm 1 is the BBC world service, Alarm 2 is Classic FM

You can preview the station when you set up the alarm -( in fact that screen could be a general purpose radio player)

Unfortunately BBC Radio 4 is not an MP3 stream


11) Add the BBC live TV Channels

I first tried PMJ (Pimp my Joggler - thanks!) but I had a crash when I then added Opera (hence the pages here about mending a bricked Joggler!)
- so now I am adding just the features I need one by one and saving an image of the O2 partitions 1 and 2 to an Ubuntu memory stick

I put these icons
bbc1.swf bbc2.swf bbc3.swf bbc4.swf news24.swf
into a new folder
/media/appshop/tv/

I added
<app static="0" id="BBC1" title="BBC 1" loc="" icon="/media/appshop/tv/bbc1.swf" app="http://www.bbc.co.uk/emp/10player.swf?playlist=http://www.bbc.co.uk/emp/simulcast/bbc_one_london.xml"/>
<app static="0" id="BBC2" title="BBC 2" loc="" icon="/media/appshop/tv/bbc2.swf" app="http://www.bbc.co.uk/emp/10player.swf?playlist=http://www.bbc.co.uk/emp/simulcast/bbc_two_england.xml"/>
<app static="0" id="BBC3" title="BBC 3" loc="" icon="/media/appshop/tv/bbc3.swf" app="http://www.bbc.co.uk/emp/10player.swf?playlist=http://www.bbc.co.uk/emp/simulcast/bbc_three.xml"/>
<app static="0" id="BBC4" title="BBC 4" loc="" icon="/media/appshop/tv/bbc4.swf" app="http://www.bbc.co.uk/emp/10player.swf?playlist=http://www.bbc.co.uk/emp/simulcast/bbc_four.xml"/>
<app static="0" id="News24" title="News 24" loc="" icon="/media/appshop/tv/news24.swf" app="http://www.bbc.co.uk/emp/10player.swf?playlist=http://www.bbc.co.uk/emp/simulcast/bbc_news24.xml"/>

to
/media/apshop/applications.xml


12) Make it talk - load flite
I took these files from a Joggler Ubuntu USB stick on which I had previously done apt-get install flite.
They were copied to the same locations on the O2 Joggler (see the zip)
flite -t "hello world"
worked !

Also try
flite_time 10:45


13) Run scripts by pressing icons on the main O2 menu

I attempted to follow this post (many thanks!)
http://www.joggler.info/forum/viewtopic.php?f=40&t=852
I bricked the joggler a few times! (no problem)-
- the following works but I cannot get the Icon name to show -

add these files
/var/www/cgi-bin/poweroff/language.xml
<language>
<mm en="Poweroff OS" />
</language>

/var/www/cgi-bin/poweroff/poweroff.cgi
#!/bin/sh
echo "Content-type: text/plain"
echo ""
poweroff

/var/www/cgi-bin/poweroff/poweroff.swf - - - the icon - my backup copy (with thanks)

to /media/appshop/applications.xml
add the line
<app id="Poweroff" loc="" app="http://localhost/cgi-bin/poweroff/poweroff.cgi" title="Poweroff" icon="/var/www/cgi-bin/poweroff/poweroff.swf"/>
BEWARE it was some other version of this line that made the Joggler hang just after the "bubbling O2 screen with chime"
-It may have crashed because the icon being requested was absent
A full set of files for Poweroff/Reboot/Killall_tango are here


14) Run Python programs

In OpenWrt there is a cut down version of Python - Python-mini (it is 1 MByte).
I was not able to set this up in Ubuntu so copied /usr/bin/python2.6 (it is 2.1MByte) from Ubuntu for Joggler to my O2 native folder at /usr/bin/
Python-mini seems to need no support files for the simple i2c control programs I have tried so far on my nslu2 (Slug) but the Joggler Ubuntu version needs many supporting files. So I copied all of the Ubuntu folder /usr/lib/python2.6 to /media/python2.6 in the O2 native file system.
I then did -
ln -s /media/python2.6 /usr/lib/python2.6
to put a symlink into /usr/lib where Python2.6 expects to find the files.
There may be yet more files to steal from Ubuntu but so far it works - at least for this program

Sunspot Home

Joggler menu