Sunspot Home

more notes for a bad memory - - -

Setting up the Raspberry Pi with a 3.5 inch colour LCD and Epiphany browser in Kiosk mode

Objective
Show a web page in full screen (Kiosk mode) that is controlled by CGI scripts to show solar water heater performance etc.

Method
I bought a 3.5 inch 320x400 display for a Pi for under £9 from eBay
New-3-5-TFT-LCD-Touch-Screen-Module-320-480-RGB-Display-Board-For-Raspberry-Pi

It is pin sharp and colorful - I thought that 1 or 2 pixels were dead (hence the price?)
but their location is random - perhaps a data comms problem?


I loaded the img file -
raspberry_35_inch_ts.rar
from -
http://osoyoo.com/wp-content/uploads/sample code/

Load the image with Apple Pi-Baker

Set a fixed IP address in /etc/interfaces/network

# The loopback network interface - always needed here
auto lo
iface lo inet loopback

# this one for dhcp
# auto eth0
# iface eth0 inet dhcp

# this one for WIFI D-Link DWL-G122
# allow-hotplug wlan0
# iface wlan0 inet static
# pre-up ifconfig wlan0 up
# pre-up iwconfig wlan0 mode Managed
# pre-up iwconfig wlan0 essid "225"

# The primary network interface - use this for ethernet cable if WIFI above not used
# in that case disable the WIFI above with # before each line
allow-hotplug eth0
iface eth0 inet static

# set these for the LAN address
address 192.168.0.xxx
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255

# set this for the Internet modem gateway to the LAN
gateway 192.168.0.yyy
# dns-* options are implemented by the resolvconf package, if installed

# my gateway acts as a local dns-nameserver (not needed?)
dns-nameservers 192.168.0.yyy

Do not change the bootloader during the update
sudo apt-mark hold raspberrypi-bootloader

Update/upgrade the PI image
sudo apt-get update && sudo apt-get upgrade -y

Create a webserver that will be used to create the local web page at 127.0.0.1 for the Kiosk mode
sudo apt-get install apache2 -y

Note - I tried to load PHP at various point in this procedure. After all seeming to work I backed up the image with PiBake (Mac).
On the next boot I could not see the GUI screen - just a black screen tha accepted typing from the keyboard.
This happend several times.

Epiphany browser - Boot to a web page and set Kiosk mode,

Create full screen as if key F11 pressed
sudo aptitude install xautomation

At
/home/pi/fullscreen.sh
create -

#! /bin/sh
# /home/pi/fullscreen.sh

# launch the web page of choice (this one is the default that Apache creates in /var/www
sudo -u pi epiphany-browser -a --profile ~/.config http://127.0.0.1/index.html --display=:0 > /dev/null 2>&1 &
sleep 15s;

# this does the same job as pressing the F11 key to force Kiosk mode
xte "key F11" -x:0 &

then do -

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi

# kill the screen saver
#@xscreensaver -no-splash

@/home/pi/fullscreen.sh

sudo reboot

and the Pi will show the normal GUI followed by the Apache default web page in full screen mode at /var/www/index.html

It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.

There are no borders and no way to poweroff cleanly other than hitting the "Windows" key on the keyboard.
I aim to create the page from a script and add a poweroff button.

First prepare the Raspberry Pi
I need a ramdisk for changing data so as to not burn out the flash memory
Place this with 755 permissions into
/etc/init.d/graham_startup.sh

Every time the Raspberry Pi is booted the temporary RAM disk will be created - 2M means 2 Mega Bytes
it could be much larger - I use it for the output of bash scripts and the input of Blassic basic programs.

(Blassic basic acts as great glue to hold together other software including C, bash etc and can save and read files as needed.
It handles and manipulates text string in ways I can understand and remember - (unlike C !!!!).
Learn Python and C++ if you can but if you only program a couple of times a year consider Blassic as a tool to get the job done.
See a few notes at pull down menu item 12 at -> http://www.sunspot.co.uk/Projects/sweexproject.htm )

#! /bin/sh
#
# My startup script at
# /etc/init.d/graham_startup.sh
#

# note, when changed do the following at a ssh command line-
# update-rc.d -f graham_startup.sh remove
# update-rc.d -f graham_startup.sh defaults 99
#

# Now carry out specific functions when asked to by the system
case "$1" in
start)

# make a ramdisk to save the flash
mkdir /var/www/ramdisk
mount -o size=2M -t tmpfs tmpfs /var/www/ramdisk

;;
stop)
;;
*)
echo "Usage: /etc/init.d/graham_startup.sh {start|stop}"
exit 1
;;
esac

exit 0



Setting up the Pi as a webserver

Get the latest software and links
apt-get update

install Apache
apt-get install apache2

There should be a simple webpage index.html in /var/www/

see it at http://192.168.0.82


CGI scripting in bash

in :-
/usr/lib/cgi-bin/hello.cgi

put :-
#!/bin/bash
echo -e "Content-type: text/html\n\n"
echo "<h1>Hello World</h1>"

then create a link to cgi-bin in the www folder :-
ln -s /usr/lib/cgi.bin /var/www/cgi-bin

see it at http://192.168.0.82/cgi-bin/hello.cgi


Add PHP - works - but it was not stable. . . .

sudo apt-get install php5 libapache2-mod-php5 -y

To test PHP put into /var/www/php_test.php

<html>
<head>
<title>PHP test</title>
</head>
<body>

<?php
echo "<b>Hello World!</b><BR><BR>The date is ";
echo date('Y-m-d'), "<BR>and the time is ", date('H:i:s');
echo "<BR><BR>Now for some information about PHP :-<BR><BR>", phpinfo();
?>

</body>
</html>

see it at http://192.168.0.xxx/php_test.php


If there are several Raspis on the network change their host names

sudo nano /etc/hosts
sudo nano /etc/hostname
sudo /etc/init.d/hostname.sh
sudo reboot


Please email me if you want to swap notes
- especially if you do a better job !!!!
and/or
add i2c port expanders, thermometers, displays etc
(my next learning exercise)

SUNSPOT HOME

more to come . . .