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.
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:
iface lo inet loopback
iface eth0 inet dhcp
iface wlan0 inet static
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.
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
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.