Tweeting Raspberry Pi Info at Startup

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.

twitter
An example of a direct message generated when the Raspberry Pi boots.

The script uses Python and the Tweepy library for accessing the Twitter API. I’ve also used the get_ip_address() as published here.

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
/path/to/startup.py

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.