Metering the meter cupboard

In this article we will look at my meter cupboard and the meters inside it. In future articles we will see how I used a microcontroller and some sensors to meter the meters (at the time of writing the electricity meter works). From left to right, these are the electricity, gas and water meter:

Electricity

The electricity meter is a relatively new one with a digital display and a flashing LED. This LED flashes one thousand times for each kWh consumed, i.e. once per Wh.

Gas

The gas meter doesn’t have a flashing LED or something comparable. There is hope however, because there is a reflective area on the digit ’6′ at the far right of the display, just left of the ‘m2′. It also looks like there is some magnetic material in one of the last two digits, so there are actually two ways to go with this meter.

Water

The water meter doesn’t have a flashing LED or a reflective area anywhere. It also doesn’t have a colored dial, which most commercial water meter detectors use. There is a tiny bit of hope in the hole below ‘PR’. Using a magnetic sensor, I found some fluctuation in the values, but nothing consistent so far. The orientation of the sensor seems to be important, so I will fiddle a bit more with this one in the future.

Installing SqueezeCenter on Ubuntu

logitech
After installing a brand new Ubuntu 9.04 Server, add the squeezecenter repository to /etc/apt/sources.list

deb http://debian.slimdevices.com stable main

Then tell apt to reload everything:

sudo apt-get update

Now try to install squeezecenter:

sudo apt-get install squeezecenter

The following seems to be necessary to install MySQL to the machine (which I didn’t select during installation):

sudo apt-get -f install

Finally, connect to the new squeezecenter software by directing your webbrowser to port 9000 of the machine you installed the software on.

A Linux NAS setup with software RAID and incremental backup

harddisk

Characteristics

I wanted to make my own Network Attached Storage (NAS) device with the following characteristics:

  1. It should have lots of disk space and new disk space should be easy to add.
  2. The primary storage should be redundant: if one disk fails, the data should still be there.
  3. Important data on the primary storage should be backed up automatically and incrementally to secondary storage.
  4. It should be able to run VMware.

Hardware

The following hardware was used to construct the NAS:

  • Antec NSK4480 mini tower with 380W power supply
  • Asus M3N78-CM GeForce 8200 SATA2 mainboard
  • AMD Athlon X2 5050e 2.6GHz 1MB 45W AM2 processor
  • Scythe Ninja Mini processor cooler
  • Kingston 2x2GB DDR2 SDRAM PC6400 memory
  • One Samsung HD501LJ 500GB disk
  • Three Western Digital WD10EACS 1TB disks
  • Samsung SH-S223F DVD player

nas-antec-nsk4480nas-asus-m3n78-cmnas-amd-athlon-x2-5050enas-scythe-ninja-mininas-westerndigital-wd10eacsnas-samsung-sh-s223f

The 500GB disk will be used to hold the operating system, Ubuntu 8.10 desktop, and the backup of the most important files. The three 1TB disks will be bundled together into a software RAID5 set, as shown in the following diagram:

nas-disks

Software RAID

We start by installing the operating system, Ubuntu 8.10 desktop for i386 systems. I choose the desktop version because I wanted to be able to access the VMware GUI on the NAS itself. I started with the 64 bit version of Ubuntu 8.10, but it was harder to install and it seemed slower than the i386 version. It does mean that we loose some of the 4GB RAM, but that is not a big concern for me.

After installing the OS, we move on to the partitioning of the three disks that will form the RAID5 set. We do this by installing the program gparted which is ideal for partitioning disks from a GUI:

sudo su -
apt-get install gparted
gparted

In gparted, create a single partition on the three RAID5 disks.
Next, create the RAID5 set:

apt-get install mdadm
mdadm --create /dev/md0 --level=5 --chunk=128 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1

Create a filesystem on the RAID5 set we just created:

mkfs.ext3 -b 4096 -R stride=32 /dev/md0

Create a mountpoint for the RAID5 set:

mkdir /data

Add an fstab entry by editing /etc/fstab:

/dev/md0   /data   /ext3   defaults   0   0

Finally, mount the RAID5 set:

mount /data

Incremental backup

The most important files on the NAS need to be backed up to the disk that also holds the operating system. The program rshapsnot is ideal for this task. It will do fast incremental backups that are browsable on the filesystem. So there’s no need to use a special program to restore the backup. Just copy the files and you’re done.

Install rsnapshot:

apt-get install rsnapshot

Edit the rsnapshot configuration file /etc/rsnapshot.conf:

snapshot_root /backup/
cmd_cp /bin/cp
cmd_ssh /usr/bin/ssh
cmd_du /usr/bin/du
cmd_rsnapshot_diff /usr/bin/rsnapshot-diff
interval hourly 6
interval daily 7
interval weekly 4
interval monthly 12
backup /data/important_files/ localhost/

This configuration file tells rsnapshot some basic things like the whereabouts of some needed programs and which directories it should backup. In our case, the directory /data/important_files is backed up to the directory /backup. It also tells that there should be 6 “hourly backups”, 7 “daily backups”, 4 “weekly backups” and 12 “monthly backups”. The reason I use quotation marks here, is that you yourself have to setup the cron jobs to actually run rsnapshot at the time you want. Run the following command:

crontab -e

and add the following lines:

# m h  dom mon dow   command
0 */4 * * * /usr/bin/rsnapshot hourly
45 23 * * * /usr/bin/rsnapshot daily
30 23 * * 0 /usr/bin/rsnapshot weekly
15 23 1 * * /usr/bin/rsnapshot monthly

This crontab will run the different backups in the following way:

  • The “hourly backup” is run every four hours (denoted by the hour value of */4) on the hour (denoted by the minute value of 0).
  • Every day at 23:45, the “daily backup” is run.
  • Every sunday (denoted by the day-of-the-week value of 0) at 23:30 the “weekly backup” is run.
  • Every first day of the month (denoted by the day-of-the-month value of 1) at 23:15 the “monthly backup” is run.

In combination with the “interval hourly 6″ line in the rsnapshot configuration file, this means that the last 24 hours are covered with 6 backups. In the same way we can see that 7 days are covered in the last week, 4 weeks are covered in the last month and 12 months are covered in the last year.

File sharing

To actually start using the NAS, we will now install the Samba package:

apt-get install samba

Finally, we edit the configuration file /etc/samba/smb.conf:

security = user
[data]
   comment = Data
   browseable = yes
   path = /data
   guest ok = no
   read only = no
[backup]
   comment = Backup
   browseable = yes
   path = /backup
   guest ok = no
   read only = yes

This will make the primary storage accessible read-write through \\nas\data and the backup accessible read-only through \\nas\backup.

Personal Video Recorder (PVR)

Introduction

On this page you can find information about the Personal Video Recorder I’ve built. I wanted to replace my old VCR with a more versatile machine with higher quality audio and video. There are commercial systems out there that can do some of these things, but not all that I wanted:

  • Record and playback tv shows in high quality
  • Electronic program guide, on television and web
  • Play video files (mpeg, divx) from the network
  • Play audio files (mp3) from the network

Because the PVR will have its place in the livingroom, there are some other criteria this machine needs to fulfill: it has to be good looking and really quiet! I opted for a standard PC, not a special fanless one, because it makes it much easier to upgrade and less expensive. Just two fans remained then: one in the power supply and one on the processor.

Case and power supply

I began looking for a nice PC case and ended up with the DIGN-3E case, which can hold a standard ATX motherboard and power supply. It has a silver look (also available in black and gold) that matches audio and video components and is of equal width (430 mm). A VFD display (type HD44780) is mounted on the front to display status information.

pvr-dign-3epvr-silenx-psu

The DIGN-3E doesn’t have a power supply, so I searched the web for a suitable one. SilenX sells really quiet power supplies (< 14 dBA), so I used one of these: 400 Watt iXtrema PSU. This is more than the power needs for the PVR in its current state, but leaves some room for future components.

Motherboard and processor

Mainly because of its speed / price ratio I chose an Athlon motherboard and processor. The motherboard is an Asus A7N8X-X and the processor is an AMD Athlon XP 2800, which I downclocked to reduce its temperature. The processor is cooled by another silent (< 14 dBA) component from SilenX: MCX-462V HSF Combo for Socket A/462.

pvr-asus-a7n8x-xpvr-amd-athlon-xp-2800pvr-silenx-cooler

Videocard and TV card

The videocard had to be fanless, have a tv-out and be supported under Linux. These criteria led me to use the Asus V9400, which uses the nVidia nForce2 chipset. To be able to view and capture tv shows, I use the PVR-350 from Hauppauge. It can record and playback MPEG2 in hardware, relieving the processor from this task. It also has an IR remote and receiver, making it possible to sit on the couch and control the PVR.

pvr-asus-v9400pvr-hauppauge-pvr350

Hard drive and DVD drive

Finally, the hard drive is a Seagate Barracuda 160 GB. Because of its fluid bearing, it is reasonably quiet. For performance, it might have been better to have a specific hard drive for the operating system and one for the media files. However, this makes the system less quiet and the performance hasn’t been an issue so far. For convenience I also installed a DVD drive, one I already had lying around: Afreey 8x DVD.

pvr-seagate-barracudapvr-afreey-dvd

The complete picture

After carefully placing all components into the case, the following picture was formed:

pvr

Software

Several software packages exist to transform a PC into an PVR. One of the most promising I stumbled across is MythTV. It is an open source program and runs on Linux. Some of its features are:

  • Pause, fast-forward and rewind live television
  • Record and playback tv shows, using the electronic program guide
  • View pictures and videos
  • Listen to audio
  • See weather predictions
  • Play games