The Life of (my) Pi


Ok. So since this was written things have moved on. See Amateur radio.
So the Pi is no longer running the printers or lives on a plank.
It now lives under the TV running the websites alongside a 2nd Pi that I use for file-sharing. No pic of that as yet.
The main reasons were:
1. to make room for the radios and,
2. radio interference on 2m from the cat5 cables (they're now running via wifi).

So I got myself a Raspberry Pi.
pic of a RPi
The question was, what should I do with it?

Unlike most ISPs the one I currently use does not provide any webspace for personal use.
So to get round this problem I created this (and a couple of other) websites and host them from my home PC.
Of course this means I have to be on-line 24/7.
This makes the PC (6 core AMD Phenom II 1100T @ 3.3GHz) a bit overpowered for most of the time just serving the odd web page.
It used to sit and hum all day and all night, using some 300W of power.

Now since those very nice people at British Gas sent me an electricity monitor pic of a power monitor, even though I don't get electricity from them, I have become aware of just how much this sort of thing costs me.
Since I'm no longer working and bringing home silly amounts of money, I do need to watch the pennies.
A few quick sums show that the PC being on 24/7 was costing me about £1.00 a day.
Oh if only I had a low power computer capable of running a web server!

Oh wait! I do.

The RPi is rated as needing 5 volts at 750 mA, most of which is needed to run a keyboard and mouse.
Of course, a web server can be run headless (no keyboard, mouse or monitor) and so would, I estimate, only need 500 mA at most.
That is 2.5 Watts, or 120 times less or about 0.83% of that used by the big PC which can now be off most of the time.
So the savings on the cost of electricity will be £1.00 a day or 1 Raspberry Pi a month!

There are now 3 RPi in the home and as I've had one of them running the websites since mid June 2012, they are all paid for.

And here it is. stuck to the wall with a bit of double sided tape and an elastic band. (It has gained a case since then.)
pic of my Pi stuck to the wall

Oh and how cruel am I? I find that the little grey box that acts as a print server on my home network uses 15W.
You can guess what I did. Poor old Pi gets CUPS installed and now handles the print requests as well.

As I write I have a project in hand to use the RPi GPIO pins to turn the printer on and off, at the mains, as needed.

[Update Feb 2013]
Disaster! after 8 months of continuous use, well OK excluding take down for backups etc, the Pi (above) running my web sites died. Luckily it did so within 24 hours of the last backup.
A spare Pi and the backup SD card were quickly installed to resume web access.
After some trial and error I proved the SD card had failed. Trying to copy a small file to the SD card failed with many write errors over several hours. Although the card would still read.
Lesson learnt. The 32Gb SD HC10 card only lasts about 8 months in continuous use.
Good news is the shop where I bought it gave me a free replacement :-)

Rule #1: always have an up to date backup.
Rule #2: see #1 above.

[Update 8th March 2013]
pic of my Pi on its wooden plinth
The printer control project goes well and RPi is now mounted on a slab of wood (well tied on with a couple of bits of twine and an elastic band!) along with (right) a set of 8 relays. Five of which control the first 5 mains sockets along the bottom. (The right most socket is a master and is always ON. There is a USB2 hub on the left. As this has a 2.5A PSU, plugged in to the right, I am taking the power from the hub to feed the RPi, via the GPIO pins, and the relay bank.

The hub currently has a wifi dongle in it but is actually for making the USB connections to the printers and a K/b and Mouse should they ever be needed. I normally run the RPi headless and talk to it via ssh from one of the other computers on the network. After I've shown it of at the Rasberry Pi Jam tomorrow (9th March, Norwich) it will be getting screwed to the wall.

closeup of a wire wrap
I used an old computer connection method of wire wrapping the terminals.

I have two bash scripts on the SD card to control the relays. The first, called relay.sh, simply activates the required GPIO pin to pick or drop the relay which I have numbered 1-8 with 1 being on the right.

Then I have another script caller printer_watchdog.sh which is started by cron at reboot. This periodically monitors the two printer queues and if it is not empty the power is applied to the printer.
If the queue is then empty for 15 minutes the power is dropped again.

Here are the scripts for those who are interested:

relay.sh

#! /bin/bash
#
# script to pick and drop relays 
#
# usage is relay <1-8> <0|1>
#
#
if [ "$1" = "" ] || [ "$2" = "" ]
  then
    echo "usage: $0 <1-8> <0|1>"
    exit -1
fi

if [ "$1" -lt "1" ] || [ $1 -gt "8" ]
  then
    echo "usage: $0 <1-8> <0|1>"
    exit -1
fi

if [ "$2" -lt "0" ] || [ $2 -gt "1" ]
  then
    echo "usage: $0 <1-8> <0|1>"
    exit -1
fi

#relay number to gpio mapping
# relay:  1  2  3  4  5  6  7  8
#  gpio: 17 22 21 18 23 24 25  4
case $1 in
[1])
  gpio=17
  ;;
[2])
  gpio=22
  ;;
[3])
  gpio=21
  ;;
[4])
  gpio=18
  ;;
[5])
  gpio=23
  ;;
[6])
  gpio=24
  ;;
[7])
  gpio=25
  ;;
[8])
  gpio=4
  ;;
esac

if $(test -d "/sys/class/gpio/gpio$gpio")
then
    true
else
    echo "$gpio" > /sys/class/gpio/export
    echo "out" > /sys/class/gpio/gpio$gpio/direction
fi

if [ "$2" = 0 ]
then
    echo "1" > /sys/class/gpio/gpio$gpio/value
else
    echo "0" > /sys/class/gpio/gpio$gpio/value
fi


and here is the printer watchdog script:

#! /bin/bash
#
# script to apply and drop mains power from the printer(s)
# so it is (they are) only powered up when needed.
# v2.0

timer1=0
timer2=0
count1=0
count2=0

while true
do

count1=$(lpstat -o HP_DESKJET_660C | wc -l)
count2=$(lpstat -o HP_Color_LaserJet_2605 | wc -l)

#echo $count1 $timer1 $count2 $timer2 > /home/nev/printer_watchdog.txt

if $(test $count1 -gt 0)
  then
  
  if $(test $timer1 -lt 10)
    then
    /home/nev/bin/relay.sh 1 1
    timer1=10
  fi

  else

  if $(test $timer1 -eq 1)
    then
    /home/nev/bin/relay.sh 1 0 
    fi

  if $(test $timer1 -gt 0)
    then
    timer1=$(( $timer1 - 1 ))
    fi
fi

if $(test $count2 -gt 0)
  then
  
  if $(test $timer2 -lt 10)
    then
    /home/nev/bin/relay.sh 2 1
    timer2=10
  fi

  else

  if $(test $timer2 -eq 1)
    then
    /home/nev/bin/relay.sh 2 0 
    fi

  if $(test $timer2 -gt 0)
    then
    timer2=$(( $timer2 - 1 ))
    fi
fi
sleep 90 

done


My wish list: A pi with mounting holes.


Contact the author of this page

Valid HTML 5.0    Valid CSS!    Raspberry Pi Logo

This website runs on Raspberry Pi hardware.
© Copyright 1995-2019 Nev Young