I recently bought a Camera Module for the Raspberry Pi. One of the main reasons for getting one was to see if I could set up a live stream from the camera that would be accessible from a web browser or mobile device – partly because it seemed like an interesting project, and partly so I can keep an eye on our dog while I’m away from the house.
It turned out that this was very achievable, but it does require quite a bit of configuration to get things working. I thought I’d document my process here, in the hope that my experiences might help anyone else trying to get a live stream up and running from their Raspberry Pi.
I’m using the following software to enable the live stream:
nginx with rtmp
Safari (OS X or iOS)
Assuming that you have a Raspbian installation up & running, I’ll run through the configuration of the other items below.
I’ve spent a bit of time over the last few months setting up my Raspberry Pi collection. I now have 3 devices running between my home and my office with a variety of services, including Internet Radio streaming, XBMC, file shares, web and chat servers, and so on.
Two of these Raspberry’s are running full-time without a monitor, which sometimes causes a problem – what happens when the IP address changes? Without a monitor attached, it can be difficult figuring out what the IP address of the Raspberry is. Obviously I can have a static IP address on my home network, but the work network is a different story (without going to a lot more trouble, anyway).
So, here’s a small Python script that runs when the Raspberry starts up, and sends me a direct message over Twitter with the Raspberry’s current hostname, and the IP addresses for eth0 and wlan0.
The script uses Python and the Tweepy library for accessing the Twitter API. I’ve also used the get_ip_address() as publishedhere.
Installation & Usage
You can get the current version of the script from GitHub. Before using the script, you will need to make a few changes.
First, you will need a separate Twitter account for the Raspberry script to use. Once created, follow these instructions to install Tweepy and generate the secret keys you will need for the Twitter API.
Update startup.py and populate the CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY and ACCESS_SECRET with the values that have been generated for your account. You will also need to set the to_user value to be your Twitter @username. Once you’ve entered these values, you can run the script. This should send you a Twitter DM similar to the one pictured above.
Running the script at startup
The exact details may vary depending on which distribution you use – in my case, I’m using Raspbian – to run this script at startup, simply add the following line to your /etc/rc.local file:
#Send Startup Tweet
Also make sure to chmod 755 the script to ensure it is executable. Now, each time the Raspberry boots up, it will DM you with the hostname and IP address information.