PI PROJECTS: SMS with Python
What is it?This simple python program will allow you to send an SMS or text message from your Raspberry Pi. It can then be incorporated into other programs or even text you every time your Ras.Pi. boots up.
Sign up for an AccountFirst you need to register your phone for a Twilio account and Twilio number. This is free but will only allow you to send SMS to and from the registered phone. You will receive a verification code via SMS to the registered phone. When promoted enter this onto the Twilio site to authenticate your account and phone.
Next visit the Dashboard page which will display your Account SID and your AUTH. Token. Keep these safe and private but, make a note of these for the Python program.
|
How To:Connect and Boot up your Raspberry Pi, In the LX Terminal :
Update your Pi sudo apt-get update Upgrade your Pi sudo apt-get upgrade Next install the Twilio Python module sudo easy_install twilio OR sudo pip install twilio Open Python IDLE and type the following code, a modified version of the program is available at the end for your to download. from twilio.rest import TwilioRestClient account_sid = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # Enter Yours auth_token = "XXXXXXXXXXXXXXXXXXXXXXXXXX" #Enter Yours client = TwilioRestClient(account_sid, auth_token) message = client.messages.create(to="+44mobilephonenumber", from_="+44yourtwilionumber", body="Hello there!") print message.sid Because your Twilio account is a trial account you can only send and receive from the validated phone number Replace the XXXXXXX with your SID code and AUTH. Token. Save with a suitable file name for example send_sms. Remember also to use +44 and remove the 0 before the beginning of the phone numbers. To run, open the LX terminal sudo python send_sms.py Depending on your mobile phone reception, you should receive your text in a within a few minutes Code to send any SMS message: Download here Coming Soon
|