Skip to content
ggodart edited this page Nov 3, 2014 · 24 revisions

Misterhouse on the BeagleBone Black

Introduction

This page describes how to get Misterhouse running on a BeagleBone Black with the standard Debian build.

The BeagleBone Black is another Single Board Computer, in many ways, similar to the Raspberry Pi, it has less video capability, but a more powerful chip (reputed to be twice as powerful as the Pi), it certainly feels more powerful for non-video operations, for example the chromium browser is perfectly usable, whereas the browsers on the pi really struggle. On the other hand if you are building an XBMC device you are probably better off with the Pi. On my Misterhouse installation, CPU usage is about half what it is on the Pi.

At the time of writing the BeagleBone Black is retailing at about £50 in the UK. To this you will probably need to add a USB hub (it only has one USB socket), SD card(s), Power Supply, USB-Serial adaptor, and a USB Sound card.

This page starts by getting everything running on a micro SD card then describes the steps needed to make it work off an NFS file system.

Some of the commands need to be done as root, so you need to do the following before running them, the remainder can be done as the default debian user

$ sudo -s

Commands that need to be run as root are preceded by a # instead of a $.

This is a work in progress document being updated as I solve problems with the build, please be patient.

Flashing the image onto an SD Card

The internal flash drive in the BeagleBone is very small and there is hardly any room to install anything else, especially if you are going to create a lot of log files like Misterhouse does, so its best to get a 4 Gby micro SD card and flash an image onto it and boot from the SD card as described here.

Firstly I created a Debian eMMC flasher image to update the on-board flash, then I repeated the process to create a standard SD based Debian image. NOTE: After updating the on-board flash image, the SD based image should boot automatically without holding the boot button as in the instructions.

Things WILL GO WRONG during your install so its a good idea to take an image backup of your micro SD card at regular intervals using the Windows Disk Imager or whatever else you used to create your micro SD card. NOTE: remember to press the READ key when making a backup.

Change the passwords

The default password from the images above for the debian user is temppwd, and the root password is blank, use

# passwd

as root to change them.

Extending the Disk image on your SD card

The standard Debian image is only 2 Gby so you need to extend it to get access to the rest of the space on your card as described here.

Changing to Static IP address

By default the BeagleBone uses DHCP and briefly flashes the IP address on the screen during boot. Here is how to change it to use a static address with wired Ethernet so you can easily use services like the web server and ssh to connect to your BeagleBone, I've not tried to use a USB WiFi card.

Start by editing /etc/network/interfaces as root:

# nano /etc/network/interfaces

Then add your address, netmask and gateway below the eth0 interface - remember to un-comment it first - it should look something like this;

iface eth0 inet static
address 192.168.10.47
netmask 255.255.255.0
gateway 192.168.10.1

NOTE: If you are using wired Ethernet with a fixed IP address you should comment out the USB0 interface as it seems to interfere with eth0 on startup.

Next edit resolv.conf as root to add the address of your nameserver, which is often the same as your gateway e.g.

# nano /etc/resolv.conf

and add this line:

nameserver 192.168.10.1

to point to your Name server (the gateway in this case).

Reboot and test the network.

$ ifconfig -a

will show your network parameters.

Disable default services

By default the Beaglebone will start apache and a DHCP server. To disable these run the following;

# update-rc.d apache2 disable
# update-rc.d udhcpd disable

Update all debian packages

Update the packages as root as follows;

# apt-get update
# apt-get upgrade

Audio output

The BeagleBone does not have an analogue audio out, by default it only uses the HDMI to the TV for audio, so to connect an amp or headphones you will need to get a USB sound card. here are the steps you need to do to get this working.

I've not attempted to get audio input working.

Install the audio packages that are needed as root

# apt-get install alsa-base alsa-utils flite

Insert the USB card, reboot, then check that the BeagleBone can see the USB Sound Card;

$ aplay -L

You should see something that contains;

.....
default:CARD=Device
 USB PnP Sound Device, 
 USB Audio Default Audio Device
.....

Next do a speaker test with the following;

$ speaker-test -D default:Device

You should hear white noise from a headset or speakers connected to the USB sound card, be sure to replace the value after -D with a device from the output of your own aplay -L results. Check the volume with the following command: NOTE the BeagleBone will probably set your USB to Audio Card 1;

$ alsamixer -c 1

Note the 1 refers to the Audio card number and by default flite looks for card 0 so next you need to configure alsa to look for card 1 as follows;

$ nano /home/debian/.asoundrc

and create a file that contains;

defaults.pcm.card 1

Now you can test flite and aplay;

$ flite -t "hello world"
$ aplay /home/debian/mh/mh/sounds/sound_beep1.wav

If this does not work (and mine does) try with HDMI disabled, this of course means that you can only access your BeagleBone via ssh from then on.

$ nano /boot/uboot/uEnv.txt

Remove the comment from the line after where it says

##Disable HDMI

so it looks like this

##Disable HDMI 
cape_disable=capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN

Reboot and repeat the tests above

NOTE: I initially used a £ 2.30 card from ebay and the sound quality was awful. I've just bought a more expensive Creative one and it is really good.

Set locale and time

Edit /etc/locale.gen and un-comment the locale you need and comment out the US one if you don't live there.

I live in the UK so its en_GB.UTF8.

# nano /etc/locale.gen

Then run

# /usr/sbin/locale-gen

See @http://derekmolloy.ie/automatically-setting-the-beaglebone-black-time-using-ntp/ regarding setting the time. In the UK I do the following;

# nano /etc/ntp.conf

and add;

server 0.uk.pool.ntp.org
server 1.uk.pool.ntp.org
server 2.uk.pool.ntp.org
server 3.uk.pool.ntp.org

Now link your localtime file - the next lines show how to do it for me in London

# rm /etc/localtime
# ln -s /usr/share/zoneinfo/Europe/London /etc/localtime

Install additional packages for Misterhouse

Misterhouse needs a number of packages to be installed, I've added a few more that I find useful (like locate). If you use a database you will have to install that too at this time (I don't so I've not tested that at all).

# apt-get install unzip telnet libgd2-xpm-dev libdb-dev
# apt-get install tk-dev ntp libgd-graph-perl libio-compress-perl
# apt-get install libgd-gd2-perl locate 

Install required perl modules

A normal install of Tk fails during the tests, so you have to force install it. It seems to work, but I've not tested it extensively as I don't use Tk, if you don't either I would suggest you skip installing the 2 Tk modules and set tk=0 in you mh.ini file.

# perl -MCPAN -e shell
force install Tk
install Tk::JPEG
install DB_File
install Term::ReadKey
install Time::HiRes
install Audio::Mixer
force install GD
install Text::LevenshteinXS
install Device::SerialPort</span>

The following are optional depending on if you want to interface to a database server and a gmail client

install DBI
install DBD::mysql
install Email::Send::Gmail

then exit MCPAN

exit

Get Misterhouse

This is how to get the latest code as of July 2014. I use the following directory structure; /home/debian/mh/... is Misterhouse home and /home/debian/mh/mh/... is for the Misterhouse distribution.

Here is how I set this up

$ cd /home/debian
$ mkdir mh
$ cd mh
$ wget https://api.github.com/repos/hollie/misterhouse/zipball/v3.1
$ unzip -aU v3.1

I then rename the home directory of this to mh as follows so the root directory of Misterhouse becomes /home/debian/mh/mh.

$ cd /home/debian/mh
$ mv hollie-misterhouse-v3.1-0-g24b71a5 mh

Note the file name above may change with new releases of Misterhouse.

There is a SerialPort.pm in the Misterhouse distribution that does not work on Beaglebone Black, so you need to rename it as follows so that perl uses the correct one you installed above;

$ cd /home/debian/mh/mh/lib/site/Device
$ mv SerialPort.pm SerialPort.pm.old

Check .ini parameters and start testing

My mh.ini is in

/home/debian/mh/mh.ggb.ini

in the following examples.

Check that you have something like the following in your mh.ini file.

# Misterhouse ini file saved in mh.ggb.ini
# CM11 port
cm11_port=/dev/ttyUSB0
x10_errata=1
# The default Apache install opens on the same port as mh, I disable
# apache, but for testing I also change the http port in mh.ggb.ini
http_port = 8077
# Set up flite for TTV
voice_text = flite
voice_text_flite = /usr/bin/flite
voice_text = flite
voice_names = male=>male1, mike=>male1, sam=>male2, elder_male => male3, mary=> female
# and the sound player
sound_program=aplay

Next you need to set up the .ini environment variable e.g.

$ export mh_parms=/home/debian/mh/mh.ggb.ini

Now you are ready to test Misterhouse.

If you don't set up the environment variable to point to your own mh.ini file it may fail if you also did not disable Apache because of the conflict on the port number described above.

The following will then start Misterhouse.

$ cd /home/debian/mh/mh/bin
$ ./mhl

If that works, you are ready to set up the environment to run it automatically when the system boots and customising it to your home.

Automatic startup

Create a script to start mh as follows;

$ sudo -s
# mkdir /opt/misterhouse
# chown debian /opt/misterhouse
# exit
$ nano /opt/misterhouse/mh.sh

This should contain;

#!/bin/sh 
# this is the script that starts misterhouse on startup, it lives in /opt/misterhouse 
# make sure the next line points to YOUR .ini file, not mine 
export mh_parms=/home/debian/mh/mh.ggb.ini 
# The next line starts mh 
/home/debian/mh/mh/bin/mh > /opt/misterhouse/mh.log 2>&1 &

This should be made executable;

$ chmod +x /opt/misterhouse/mh.sh

Now create the start/stop script.

# nano /etc/init.d/mh

This should contain;

#! /bin/sh 
### BEGIN INIT INFO 
# Provides: mh 
# Required-Start: $syslog 
# Required-Stop: $syslog 
# Default-Start: 2 3 4 5 
# Default-Stop: 0 1 6 
# Short-Description: mh server 
# Description: 
# Starts and stops misterhouse snd lives in /etc/init.d/mh 
### END INIT INFO 
# Misterhouse automatically generates a PID file here: 
# you may need to change this location 
PID=/home/debian/mh/GGBdata/mh.pid 
# Use this command to start the proxy 
# this just calls the other script that does the real work 
DAEMON=/opt/misterhouse/mh.sh 
# routines to start and stop Misterhouse 
# Start mh 
start(){ 
 echo "Starting Misterhouse" 
 /sbin/start-stop-daemon --start --background --quiet --chuid debian --exec $DAEMON echo "" 
} 
# Stop mh 
stop(){ 
 echo "Stopping Misterhouse" 
 /sbin/start-stop-daemon --stop --quiet --pidfile $PID 
} 
# deal with the command line variables 
case "$1" in 
 start) start ;; 
 stop) stop ;; 
 restart) stop sleep 5 start ;; 
 *) 
 # invalid command, so display the usage options.
   echo "Usage: /etc/init.d/mh {start|stop|restart}" 
   exit 1 ;; 
esac 
exit 0

Change permissions to make it executable.

# chmod +x /etc/init.d/mh

Test this with

$ /etc/init.d/mh start

and

$ /etc/init.d/mh stop

Next make this run at startup with the following command;

# update-rc.d mh defaults

Make life easier with some aliases and cosmetics

Please note that you may need to adapt these to your file locations.

First aliases

$ nano /home/debian/.bash_aliases

I find the following useful;

alias mh=/opt/misterhouse/mh
alias mhstart='sudo /etc/init.d/mh start'
alias mhrestart='sudo /etc/init.d/mh restart'
alias mhstop='sudo /etc/init.d/mh stop'
alias taillog='tail -f /home/debian/mh/GGBdata/logs/print.log'
alias tel='telnet localhost 1234'

Now cosmetics

My installation had </home/debian/Desktop owned by root so I could not add items to the desktop by right clicking on them from the task bar, simple fix is;

# chown debian /home/debian/Desktop

Watchdogs

I have 2 watchdogs, one to restart Misterhouse in case it crashes and the system one to reboot the whole machine. The Misterhouse watchdog is implemented by having a routine that writes to /home/debian/mh/GGBdata/watchdog every minute. The following crontab script is also run every minute to check if the file has been updated within the last 3 minutes, if not it restarts Misterhouse.

#!/bin/sh 
# script run by crontab every minute 
WATCHDOGFILE=/home/debian/mh/GGBdata/watchdog 
# if WATCHDOGFILE hasn't been touched in 180 seconds, restart MisterHouse 
MAXDIFFERENCE=180 
watchdog=`stat --format=%Y $WATCHDOGFILE`; 
now=`date +%s`;
difference=$(( $now - $watchdog)) 
if [ $difference -gt $MAXDIFFERENCE ]; then 
  echo "Misterhouse needs restart" 
  /etc/init.d/mh restart 
fi

For instructions on how to use the Beaglebone internal watchdog see http://beaglebone.cameon.net/home/watchdog-timer. I'm planning to use the same script as above to write to /dev/watchdog at least once per minute, if this write does not occur, the device should reboot. NOTE: I've implemented this but note yet tested it.

Move to NFS file system

The aim here is to still boot from the SD card, but to mount the root file system from an NFS server so all subsequent disk IO is on the server thus we have flexibility to make backups and don't wear out the SD card, it also should be a bit quicker. There are several comments on the web about how to do this, but many rely on non-standard distributions and are often incompatible with the current release I'm indebted to these contributors for help in getting this to run. The method below is based on the standard distribution available from the BeagleBoard web site.

First set up a NFS shared drive, how to do this varies depends on the device you are going to use. I use a Synology NAS and its very straightforward through its web interface, there are plenty of pages on the web for other platforms.

The IP address of my NFS server is 192.68.10.35 and the share on it is located at /home/bone. The fixed IP address of my BeagleBone is 192.168.10.47.

Next install the packages on your Beaglebone to NFS mount your drive and do a test mount.

# apt-get install nfs-common portmap
# mkdir /mnt/nfs
# chmod 777 /mnt/nfs
# mount -o nfsvers=3 192.168.10.35:/home/bone /mnt/nfs

Clean up after cpan as it creates lots of temporary files that you don't need any more.

# rm -rf /root/.cpan/build/*
# rm -rf /root/.cpan/sources/authors/id
# rm -rf /root/.cpan/cpan_sqlite_log

If you haven't done so before, now is a really important time to make an image backup of your SD card, as things are very likely to go wrong.

Now copy over everything to the NFS disk - a bit overkill I know, but you should have plenty of space on your hard drive.

# cp -axv /. /mnt/nfs/.
# cp -axv /dev/. /mnt/nfs/dev/.

This takes AGES, it is much quicker if you can mount your micro SD card on the same machine as the NFS share and copy the contents of the rootfs folder from there as root rather than over the network.

Next edit the fstab on your NFS disk

# nano /mnt/fstab/etc/fstab

And add the new root partition and comment out the old one.

nfs defaults 0 0
#/dev/mmcblk0p2 / ext4 noatime,errors=remount-ro 0 1

Next backup your uEnv.txt file

# cp /boot/uboot/uEnv.txt /boot/uboot/uEnv_SDBoot.txt

Then edit it;

# nano /boot/uboot/uEnv.txt

Add the following lines - changed to match your configuration

serverip=192.168.10.35
ipaddr=192.168.10.47
hostname=MH_bbb
netmask=255.255.255.0
gateway=192.168.10.1
nfsdevice=eth0:off
nfsopts=vers=3
rootpath=/home/bone

Comment out the line that starts mmcargs as follows;

#mmcargs=setenv bootargs

add a new netargs line - note all on one line, not broken as here

netargs=setenv bootargs console=${console} ${optargs} ${cape_disable} ${cape_enable} ${kms_force_mode} root=/dev/nfs nfsroot=${serverip}:${rootpath} ip=${ipaddr}:${serverip}:${gateway}:${netmask}:${hostname}:${nfsdevice}

and finally replace the uenvcmd with this;

uenvcmd=run loadfiles; run netargs; bootz ${loadaddr} ${initrd_addr}:${initrd_size} ${fdtaddr}

My uEnv.txt looks like this;

##Enable systemd
systemd=quiet init=/lib/systemd/systemd
##note: the eMMC flasher script relies on the next line
mmcroot=/dev/mmcblk0p2 ro
mmcrootfstype=ext4 rootwait fixrtc
##These are needed to be compliant with Angstrom's 2013.06.20 u-boot.
console=ttyO0,115200n8
kernel_file=zImage
initrd_file=initrd.img
loadaddr=0x82000000
initrd_addr=0x88080000
fdtaddr=0x88000000
initrd_high=0xffffffff
fdt_high=0xffffffff
## nfs paramters - edit to match your network and nfs location
serverip=192.168.100.35
ipaddr=192.168.100.57
hostname=MH_bbb
netmask=255.255.255.0
gateway=192.168.100.1
nfsdevice=eth0:off
nfsopts=vers=3
rootpath=/volume1/beagleboot
loadkernel=load mmc ${mmcdev}:${mmcpart} ${loadaddr} ${kernel_file}
loadinitrd=load mmc ${mmcdev}:${mmcpart} ${initrd_addr} ${initrd_file}; setenv initrd_size ${filesize}
loadfdt=load mmc ${mmcdev}:${mmcpart} ${fdtaddr} /dtbs/${fdtfile}
loadfiles=run loadkernel; run loadinitrd; run loadfdt
#mmcargs=setenv bootargs console=tty0 console=${console} ${optargs} ${cape_disable} ${cape_enable} ${k
ms_force_mode} root=${mmcroot} rootfstype=${mmcrootfstype} ${systemd}
netargs=setenv bootargs console=${console} ${optargs} ${cape_disable} ${cape_enable} ${kms_force_mode}
 root=/dev/nfs nfsroot=${serverip}:${rootpath} ip=${ipaddr}:${serverip}:${gateway}:${netmask}:${hostna
me}:${nfsdevice}
uenvcmd=run loadfiles; run netargs; bootz ${loadaddr} ${initrd_addr}:${initrd_size} ${fdtaddr}

Now you can reboot and it will load from the hard disk. Test by doing a

$ df

and see the extra disk space.

I found debugging this much easier with a serial console as described @http://dave.cheney.net/2013/09/22/two-point-five-ways-to-access-the-serial-console-on-your-beaglebone-black. NOTE: Do not connect the red wire and the black wire should be nearest the power/ethernet sockets with my cable.

NOTE: You can then just use a small 2G micro SD card with this uEnv.txt for booting as everything else will be on the NFS server.

Clone this wiki locally