Wireless networking on the Raspberry Pi

In an effort to liberate my Raspberry Pi, I finally caved in and bought a wireless USB adapter. Getting it up and running was not as difficult as I expected.

The Raspberry Pi wiki has a list of verified peripherals – I found the Belkin Surf at Dion Wired for R399.

After mucking about with the /etc/network/interfaces file for a while, the wireless adapter was visible in ifconfig but not picking up an IP. I eventually resorted to the following lines in the /etc/rc.local file:

First, tell it which wireless network to connect to – replace Airport with the name of your wireless network, and put it into Managed mode:


sudo iwconfig wlan0 essid "Airport"
sudo iwconfig wlan0 mode Managed

My Raspberry Pi runs headless, so I want to hard-code the IP that it will have on my network

sudo iwconfig wlan 192.168.1.227 netmask 255.255.255.0 up

Then add the IP of your router or ADSL modem so that it can find it’s way out of your network:

sudo route add default gw 192.168.1.254

If you don’t know what gateway IP your network has you can find out on a machine that has DHCP’d an IP by using the route -n on a Linux based machine or netstat -nr | grep default on a Mac.

This next bit is a bit of a hack, but the /etc/resolv.conf get’s overwritten each time you bring up the networking. I just use sed and replace the nameserver entry with the one I want:

sudo sed s/nameserver.*/nameserver 8.8.8.8/g -i /etc/resolv.conf

I could have wasted more time trying to get the /etc/network/interfaces syntax working, but this does the job and let’s me get on with other things.

Setting up statsd under CentOS with VirtualBox

A while back I came across this post on the etsy Code as Craft blog and have been meaning to have a play with it ever since.

I decided to set it up using CentOS under VirtualBox for two main reasons. First, I try to keep my machine as clean as possible, so rather than install a whole load of additional libraries and services on my Mac, I can keep the environments separate. Having it living in a virtual machine also means I can start, shutdown or destroy the environment without it impacting my ability to carry on with my day job :) The reason to go with CentOS is because they have a nice secure minimal installation that you can get up and running quickly. I prefer to start with a base and then build on top of that with just the stuff that I need, rather than install the kitchen sink and remove the stuff I won’t be using. The rest of this post is a (hopefully) step by step guide of how I got it up and running. I started with the CentOS-6.3-x86_64-minimal.iso CentOS disk image, so I’m going to assume that you have that downloaded and also have VirtualBox installed.

When creating the virtual machine you will need to attach the CentOS-6.3-x86_64-minimal.iso disk image to the CD device, and change the networking mode to bridged. It will default to NAT, which will put the virtual machine on a private network on your machine, making it invisible to other machines on the network. Using bridged mode will allow it to DHCP an IP from your networks DHCP server or router.

After the installation is complete you can log in as root and enable the ethernet bridge. To do this, you need to edit the /etc/sysconfig/network-scripts/ifcfg-eth0 file:

vi /etc/sysconfig/network-scripts/ifcfg-eth0

modify the line that reads

ONBOOT="no"

to be

ONBOOT="yes"

(If you’ve never used vi, have a quick read of this) You can now restart the box to bring up the network interface and get it to DHCP an IP:

Your ifconfig output should now include the newly configured eth0:

I then add a non-privileged user so that I’m not always logged in as root:

useradd -m allank
passwd allank

and then install sudo

yum install sudo

After the sudo install has completed, add your non-privileged user to the /etc/sudoers file:

vi /etc/sudoers

add the line (with your username instead of mine)

allank ALL=(ALL) ALL

save the file – the file is read-only, you will need to save with :w! – and log out as root and back in as your non-privileged user.

Now we can start installing some tools we’ll use during the build:

sudo yum install wget perl make gcc git

Once that is done you can go ahead and install node.js and it’s package manager:

wget http://nodejs.tchol.org/repocfg/el/nodejs-stable-release.noarch.rpm
sudo yum localinstall --nogpgcheck nodejs-stable-release.noarch.rpm
sudo yum install nodejs-compat-symlinks npm

Once that is done you can test the node installation by creating their example hello world application:

vi example.js

add this code from the node.js site, substituting your virtual machines IP address for 127.0.0.1:

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Worldn');
}).listen(1337, '192.168.1.17');
console.log('Server running at http://192.168.1.17:1337/');

Before you fire up the example, you need to open up some ports. CentOS by default only allows incoming connections on port 22 (to allow remote SSH access) – to allow incoming connections on port 1337 (the port that the node.js example code listens on) you need to add the rule into iptables:

sudo /sbin/iptables -I INPUT -p tcp -m tcp --dport 1337 -j ACCEPT

You can now start the node.js example

node example.js

and test it by browsing to your virtual machines IP on port 1337:

Now we can grab the statsd project from github:

git clone https://github.com/etsy/statsd.git

switch to the statsd directory and create a simple config file:

vi statsdconf.js

and add the following:

{
debug: true
, port: 8125
}

we then need to add port 8125 to the allowed incoming ports for iptables so that we can send data to the statsd server from external sources:

sudo /sbin/iptables -I INPUT -p udp -m udp --dport 8125 -j ACCEPT

notice that this time we are allowing UDP traffic in on the listening port, as this is what the statsd server listens for. We’ll also want to save this rule so that it’s still there after we reboot:

sudo /sbin/service iptables save
sudo /sbin/service iptables restart

and the then we can start up statsd:

node stats.js statsdconf.js

To test it we can either run one of the supplied clients, or just write up a simple python script. I want to make sure that the data is being received from a remote host (and that our iptables rule is allowing the data through) so I created this script on the host machine:

vi stats_test.py

add this code:

import socket
sock = socket.socket( socket.AF_INET,
socket.SOCK_DGRAM )
sock.sendto("ping:1|c", ("192.168.1.17", 8125))

With the statsd server running, run the python script:

python stats_test.py

You should see the ping arrive in the console log of the statsd server:

4 Aug 08:31:29 - debugCounters:
{ 'statsd.packets_received': 1,
'statsd.bad_lines_seen': 0,
ping: 1 }
Timers:
{ 'statsd.packet_process_time': [] }
Gauges:
{}

So now that statsd is up and running, we need to install Graphite so that we can actually see the data we’re collecting in a nice visual way. Graphite runs on top of Django, and needs a bunch of libraries to build the graphs. You could run Graphite using the Django development server, but I prefer to run it under apache:

sudo yum install pycairo mod_wsgi python-memcached

To install Django easily, first install EPEL:

sudo rpm -ivh http://mirror.us.leaseweb.net/epel/6/x86_64/epel-release-6-7.noarch.rpm

then install Django and required libraries:

sudo yum install Django bitmap bitmap-fonts python-pip django-tagging python-devel

Now all the requirements for Graphite are in place, we can install the component parts (and their dependencies) using pip:

sudo pip-python install carbon
sudo pip-python install whisper
sudo pip-python install graphite-web

At this point all of the component bits are in place and just need to be configured and started. Switch to the graphite conf directory

cd /opt/graphite/conf

and copy the necessary example conf files:

sudo cp carbon.conf.example carbon.conf
sudo cp storage-schemas.conf.example storage-schemas.conf
sudo cp graphite.wsgi.example graphite.wsgi

You now need to create an apache vhost configuration for graphite. There’s a great example one here that needs minimal editing.

sudo vi graphite.conf

Add the code from the above link, and edit the line:

Alias /media/ "@DJANGO_ROOT@/contrib/admin/media/"

to be

Alias /media/ "/usr/lib/python2.6/site-packages/django/contrib/admin/media/"

Now add the graphite.conf file to the apache conf.d directory so that it loads with apache:

sudo ln -s /opt/graphite/conf/graphite.conf /etc/httpd/conf.d/graphite.conf

Switch to the graphite webapp directory and create the settings file:

cd /opt/graphite/webapp/graphite
cp local_settings.py.example local_settings.py

And then create the database:

python manage.py syncdb

You can now start the carbon cache:

cd /opt/graphite/
./bin/carbon-cache.py start

Before we start apache, we need to allow connections on port 80:

sudo /sbin/iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
sudo /sbin/service iptables save
sudo /sbin/service iptables restart

And then disable selinux (this is the access control service in CentOS that restricts access to files)

sudo vi /etc/sysconfig/selinux

change the line

SELINUX=enforcing

to

SELINUX=disabled

Then give the apache user ownership of where it will keep it’s log files:

chown -R apache:apache /opt/graphite/storage/

and then start apache:

sudo /sbin/service httpd start

You should then be able to view the Graphite front-end by visiting your virtual machine’s IP in a web browser:

The last step is to connect statsd to send it’s data to Graphite:

sudo vi statsdconf.js

add the Graphite options to the config file:

{
graphitePort: 2003
, graphiteHost: "127.0.0.1"
, debug: true
, port: 8125
}

Start node again:

node stats.js statsdconf.js

Now, if you send data to the statsd server, it will appear in the tree view on the left – select the stats you want to view the graph:

This is the process that works for me – please let me know if I’ve ignored or glossed over some crucial steps.

Online tools for an offline read

As someone who doesn’t really enjoy reading on a computer or laptop screen, I’ve always thought that the Kindle and/or iPad would fill that gap. Over the last year or so I’ve tried different methods of getting the stuff that I find and want to read over on to the Kindle and iPad. This may not be the perfect solution, but it’s the one that’s working for me at the moment.

The magic lies in using Instapaper to collate the articles I want to read and provide them in a text-only format stripped of all the navigation, sidebars and advertising. To get started simple visit http://www.instapaper.com/ and register with your email address and provide a password. To use it you simply send it the URL of the article you’re reading, and it takes care of the rest. There’s a bookmarklet that you can install as well as it being supported by a shedload of existing applications. I don’t keep my bookmarks bar visible in Safari, so I prefer to use the Instafari extension.

Another excellent source is the Zite App for iPad. With Zite (and when browsing through my feeds) I tend to skim, so I use the Read Later button built in to Zite to push it directly to Instapaper.

I also find a lot of stuff that I want to read through Twitter and my feeds in Google Reader. The iPad/iPhone Twitter app has a Read Later function built into it, but I sometimes use the Mac app or even the Twitter website, neither of which don’t have the Read Later function. So to connect these to Instapaper I use the excellent new web service called If This Then That. What this site does is let you create incredibly powerful triggers into existing web services. They’ve also effectively made my weeks of tinkering with Yahoo Pipes irrelevant. The site is currently invite only, and I’ve already used up all my invites, but if you just request on their site you should get an invite pretty fast. So what I’ve done is used the Star functions of both Twitter and Google Reader as the flag that tells If This Then That to take that article that I starred and push it to Instapaper. The interface on ifttt.com is incredibly simple to use, my current two tasks are below:


So now all the articles I’ve saved from Safari, Zite, Twitter and Google Reader are pushed either natively from the app or through ifttt.com through to Instapaper. The last step is now to get all of those articles onto the Kindle or iPad. There is an Instapaper app that you can buy ($4.99) but I ended up never using it. For the actual reading I prefer to visit the Instapaper site and download the format for Kindle and iPad. For Kindle, you can have Instapaper automatically send the articles you save through wireless delivery, but Amazon will charge a delivery fee. I prefer to simply download the Kindle .mobi format file and transfer it across over USB. For the iPad I just visit the Instapaper website in Safari and select the ePub download format.

When prompted choose Open in iBooks (assuming you have it installed) and you’ll be good to go.

The mobi and ePub files have linked contents pages and images get pulled through as well. Enjoy all the articles you collected offline.

If you find Instapaper useful (and how can you not?) please consider subscribing to their service. It’s entirely optional and right now you get nothing extra for doing it, but at $1 per month, it’s not a whole lot to support a great service!

We’re hiring!

We’re looking for some fine people to come join our team. As usual, we want digital creatives who not only understand the value of ideas, but are passionate about turning them into an awesome online experience.

Our environment is not a “traditional digital” one – expect to be immersed in and exposed to all levels of the creative process – irrespective of medium or platform. If you’re not interested in the thinking behind why we build what we do, then a you’d be better suited somewhere else. Thanks for reading this far anyways.

So for those of you who haven’t already wandered off to check Facebook, we’re looking to fill the following roles in our Cape Town office:

Senior Digital Art Director
A conceptual thinker who understands digital behavior and how we best translate that into online experiences. Loves telling brand stories through images. It goes without saying that you have the craft skills necessary for this role.

Front-end wizard
Your passion should be in making the user experience as beautiful and natural as possible. Your tools are wireframes, HTML5 and jQuery. Potential candidates should expect a test :)

While these are the specific positions that we are looking to fill right now, we’re always interested in talking to people who are excited by what they do and passionate about creating participation through their ideas. If you’re a digital copywriter or digital production manager (someone who knows how to connect the bits to make things work online) please get in touch – you never know what will pop up

If you believe that you’re the person to join our team, let me know by mailing some motivating material at hello@atplay.biz and we’ll talk.

BloodRunner

Despite the iPhone being great for gaming, I’ve never really gotten all that in to it. The only game that really caught my attention was Jimmy Pataya – thanks to Rich Mulholland for getting me hooked there. However, over the last couple of weeks I’ve been fortunate enough to watch the coming together of a new little game – BloodRunner.

You play a vampire and your only job is to get to your coffin before you run out of blood. Along the way you get to avoid, navigate and dodge holy water, stakes and sun rays. Tilt the phone in the direction you want him to run and tap the screen to jump. The gameplay is easy to pick up and deceptively addictive. Not to mention incredibly frustrating. But in a good way. The kind that keeps you coming back again and again because, you know, if I time that jump just a little bit earlier I’m sure I can get to that last drop of blood.

The entire game was designed and coded here in Cape Town by (full disclosure) 3 people I know quite well. Alan Cronje, who heads up the creative side of AtPlay, designed all of the characters, screens and sprites for the game. Etienne la Grange, who coded the Engen African Welcome diary application for us earlier this year, handled all of the actual game coding, and Werner Marais, ex-Saatchi now at Y&R, wrote all of the copy and designed the levels. This is something that they worked nights and weekends to pull together and it’s great to see all of their effort come to life.

Since I got my iPhone I’ve downloaded a lot of mediocre applications and games. This is not one of those. If you’ve got a US iTunes account I’d highly recommend you grab this and give it a whirl. If not, hold on for a bit, it should be in the SA store soon.

Can’t wait to see what they bring out next.