Raspberry Pi Fishcam
Posted by Craig H on 16 July 2013
I had security concerns over installing a wireless webcam to keep an eye on our goldfish. Such things are available cheaply off the shelf, typically manufactured in China, but I’m not willing to put a device of questionable provenance on our Intranet, especially not with a direct channel out to a server in China.
I started thinking about using a Raspberry Pi and Skype as an alternative solution. As (most of) the software would be open source, that way I would only have to trust Microsoft and the NSA not to interfere with the Skype server ;-).
My Raspberry Pi camera module didn’t arrive until this week (the first production run sold out almost immediately back in May) and, unfortunately for the plan, Microsoft have turned off the ability to register a Skype developer account in the meantime :-(. Using the Skype infrastructure with the Skypekit “headless” client would have taken advantage of all of Skype’s well-established security and routing capabilities, and the remote end could have been any device with a Skype client, but for whatever reason it seems Microsoft have decided that they don’t want people to do that.
There is a Linux security camera package called “motion”, which incorporates webcam functionality; Pi user dozencrows has adapted this to work with the MMAL interface that the Pi camera offers. Unfortunately this turned out to be too heavyweight for my purposes, using most of the CPU and giving only a low frame rate.
All I really need is to turn the camera on when a remote client connects to the Pi, transmit the video stream to be viewed on the client, and turn the camera off when the client disconnects. A venerable and admirably simple utility called “netcat” turns out to be ideal for the job:
#!/bin/sh while true do nc.traditional -l -p 1234 -c "exec raspivid -t 600000 -n -w 640 -h 360 -o -" done
We are using nc.traditional, not the plain nc, because we need the “dangerous” -c option which has been taken out of the newer versions for security reasons; it’s OK, I know what I’m doing, I’m a security professional :-).
To view the video stream, we simply connect to the Pi using the open source VLC client; this runs on most platforms including Android, Linux, MacOS and Windows. Because we are viewing a raw H.264 video stream, we have to tell VLC that by adding “:demux=h264” to the options:
The URL is constructed with the protocol tcp, the IP address of the Pi (you can find this out using ifconfig), and the port number 1234 that we chose in the netcat script above.
[Edit: the MacOS version of VLC lacks the “Show more options” part of the above dialogue. Fortunately there is a simpler way to specify the H.264 format, which also works on Windows, by including it in the protocol part of the URL like this:
There is still plenty of scope for improvement in usability, and there is no access control, but the basic functionality is working and I’m pleased to do it entirely with open source components!