Pages

Navitron

2016-05-03

Sending SMS from a Raspberry Pi

I recently discovered how to configure my Raspberry Pi to send myself SMS (text messages).  Here's how:

First, get yourself an account with Twilio. This a free online service that allows you to send SMS from your Pi to a registered phone.  Once you have registered with Twilio you get an AccountSid and Auth Token to use the Twilio REST.  Keep these numbers private.

Next step is to boot up your Pi and connect to the Internet.  In the LX Terminal type:

  sudo apt-get update
  sudo apt-get upgrade
  sudo easy_install twilio

Once installed you are ready to play with the Twilio API.  I found that this only worked in Python 2.

Here is my first 'Hello World' program.

#Send SMS from Twilio account
#Needs to use Python 2
from twilio.rest import TwilioRestClient
account_sid = "YOUR ACCOUNT SID HERE"
auth_token = "YOUR AUTH TOKEN HERE"

client = TwilioRestClient(account_sid, auth_token)

while True:
    message = raw_input("Enter your SMS message\n-->")
    message = client.messages.create(to="NUMBER TO TEXT", from_="YOUR NEW TWILIO NUMBER", body=message)

    print(message.sid)
    print("Message sent.")
...And the results...

Messages sent from my Pi to my Lumia 950.  The possibilities for custom SMS-based alerts from Pi are now limitless.
Before I go, did you know you can also send SMS from Cortana on your dektop Windows 10 PC?   You will need a Windows phone and you simply have to say: "Send SMS to <contact name>".  Give it a go now.
Sending SMS from your Windows 10 PC.

No comments:

Post a Comment