HackerSpace Monitoring with Raspberry Pi

22 03 2013

About 2 months ago, nice folks at Adafruit offered to send us a care package filled with Raspberry Pi goodness. In return, they wanted us to create something and write about it. Most of us were busy, but it seemed like a good offer, so we quickly accepted it as we thought “Well, we will have some free time, right?” Yeah, free time…

Thus arrived our care package 4 weeks ago, addressed to yours truly as I was selected to be the person responsible with the progress. Nope, it had nothing to do with me giving classes about Raspberry Pi or being experienced with embedded Linux boards; the reason is as a grad student I have a flexible schedule, enjoy all-nighters, solder fumes and programming. We discussed many projects: GPS data logger, weather display, radiation measurement server and so on. All was nice but I wanted a couple of things to try with this project: WiFi access to a hidden network (our HackerSpace has a hidden network), using a webcam, reading sensors and displaying them. That gave me an idea to have a HackerSpace status display so that we can see if anybody is in so that people without keycards can drop by. While we are at it, why not add a webcam feed to it and a temperature&humidity sensor to see if it’s a good idea to leave home (In Tokyo, summers are really hot and humid so you usually don’t wander off the regular path between home and work). That is how HackerSpace Monitor was formed.

HackerSpace Monitor during development. The switch on the left side is for status messages, there is also a wireless adapter attached to the USB hub.

HackerSpace Monitor during development. The switch on the left side is for status messages, there is also a wireless adapter attached to the USB hub.

Wireless Connection with Static IP

First we have to get access to our Raspberry Pi and get a static IP for our wireless dongle so that we can access it to get webpages and video stream. You don’t need a display (I didn’t use one) as by using a console cable (basically a USB-Serial adapter) you can access the shell through a serial terminal program. The care package had a console cable so that part is easy. With your favorite editor edit /etc/network/interfaces so that it looks like this:
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet static
wpa-ssid "ssid"
wpa-psk "password"
wpa-scan-ssid 1

The settings will change depending on your network setup. Once you made the changes, save the file, then plug in the WiFi adapter and reboot. Although plugging the adapter directly to the USB port worked, there were communication errors from time to time so use a powered USB hub. Now you can SSH into your Raspberry Pi.

Webcam Stream

The second part is streaming video from the webcam. Initially I used ffserver&ffmpeg on my laptop for trying but after a little research I found that motion is better as it can be used for motion detection and can save files. Feed runs at 2 fps which is the default setting. I wanted to have a “retro security cam” feel to this feed from the beginning so it is perfect for me. You have to make some changes to the configuration files in order to be able to use it for streaming and running the daemon but it is widely covered on the Interwebs so I won’ talk about it. I had a problem with this feed, probably because of the webcam drivers so in the demo video, there is no feed.

Getting Sensor Data

We now have to read data from a temperature&humidity sensor and a switch so that later on we can display them on the status page. The sensor is a DHT11 combined temperature&humidity sensor and the switch is an ON-OFF toggle switch. So I solder up a circuit and My initial plan was to use pure Python for interfacing but as it turns out Python and DHT11 do not play well. So I go to Adafruit website and check out DHT Humidity Sensing on Raspberry Pi with GDocs Logging. It turns out they managed to solve the problem by writing a C program and running it via Python. Neat! So I try it out and it works perfectly. Also for GPIO access I used RPi.GPIO package as it makes things so much easier. Once I verified that everything is running perfectly I was set for this part.

Serving Sensor Data

For serving webpages Apache is pretty much the standard. However, I wanted to read some data and update the contents by using websockets. One of our members suggested using Tornado for this task so I started checking it out. Using it is a bit hard at first but by looking at the example codes of Introduction to Tornado, I manages to write my own HTTP server with Python. This way I don’t have to run multiple programs and pass messages between them. After a bit wrestling with JavaScript and trying to figure out periodic callbacks I had a working program in my hand. You can download the Python code, webpage and JavaScript file from my Github. You have to change IP addresses in all the files so they match your server settings. Then run the program with the following command so that it does not stop when you log out.

sudo nohup python hsmon.py &
Of course you can set up your system to run the server code automatically after booting.

Here is a video that I took during testing:

At 0:07 I flipped the switch to the ON position, the at 0:16 I flipped the switch back to OFF position.

Currently the project is not accessible from the outside as I don’t have access to the router’s NAT but with some small changes, we can display the status on our webpage.

Hope this project helps other HackerSpaces. It was a ton of fun for me. I should thank Adafruit for the care package, Raspberry Pi tutorials and code samples. And also to THS members that helped me with their suggestions.

About these ads



One response

22 03 2013
Tokyo Hackerspace Monitor Project Built Around Raspberry Pi #piday #raspberrypi @Raspberry_Pi « adafruit industries blog

[...] out this great hackerspace monitoring project from the Tokyo Hackerspace created by Taylan Ayken with a Raspberry Pi care package that we sent their [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: