I've written before about getting the Raspberry Pi to speak the weather forecast, but did you know that you can also get the Raspberry Pi to make automated phone calls? Imagine triggering a phone call based on any event such as an appointment reminder or an update on football results. Perfect for those of us who don't have smart phones but want to remain in the know.

The phone call from your Raspberry Pi is made using an online service called Plivo. There is a minimal charge per phone call (around 1 cent) and you do not need your own webserver to make the call. You simply install the python software on your Raspberry Pi, upload an XML file of what you want to say to a webserver somewhere on the internet and then write a simple python script to make the call.

Registering, downloading and installing

First of all, head over to the Plivo site and register an account. This will give you an authentication id and an authentication token which you will need later.

Next, to install the software, you'll need to install pip on your Raspberry Pi. pip is a package management system used to install and manage software packages written in Python. To install pip, type in:

sudo apt-get install pip

Now pip is installed, you can use pip to install the Plivo software:

pip install plivo

Now your software is installed, you can create your outbound message.

Creating the outbound message

The outbound message is contained in an XML file which lives on a webserver somewhere. You will create the XML file yourself and will need some webspace to copy your XML file to. If you can host files on your Raspberry Pi then you can host the file there, otherwise find some free webspace and copy it there.

The format of the XML file is as follows:

    Congratulations! You've made your first outbound call!

You can see an example of one here.

When you've done this, you'll need to create some code on your Raspberry Pi which will make the outbound phone call.

Writing the code

To write the code, create a document on your Raspberry Pi called make calls.py. Add the following text to the document:

import plivo, plivoxml

auth_id = "Your AUTH_ID"
auth_token = "Your AUTH_TOKEN"

p = plivo.RestAPI(auth_id, auth_token)

params = {
  'to': '2222222222',    # The phone numer to which the call will be placed
  'from' : '1111111111', # The phone number to be used as the caller id
  # answer_url is the URL invoked by Plivo when the outbound call is answered
  # and contains instructions telling Plivo what to do with the call
  'answer_url' : "https://s3.amazonaws.com/static.plivo.com/answer.xml",
  'answer_method' : "GET", # The method used to call the answer_url

  # Example for asynchronous request  
  # callback_url is the URL to which the API response is sent.
  #'callback_url' => "http://myvoiceapp.com/callback/",
  #'callback_method' => "GET" # The method used to notify the callback_url.

# Make an outbound call and print the response
response = p.make_call(params)
print str(response)

Note. To place calls in bulk, separate your destination phone numbers with the “<” character (e.g., 14156667777<14157778888<14158889999).

Now save your document and run your script using python make_calls.py to make an outbound phone call on your Raspberry Pi. When the message has been read, the call will automatically hang up.

You can also play pre-recorded mp3 files using this service too. In addition to outbound calls on the Raspberry Pi, you can also receive calls and send and receive SMS/text messages. For more information, you can check out this website.


comments powered by Disqus