dgreathouse
Posts: 5
Joined: Wed Feb 12, 2014 3:18 am

Send SMS Messages from Raspberry Pi

Wed Feb 12, 2014 3:24 am

The back story to this article is pretty simple. I have a Raspberry Pi, one of those super small ARM computers that cost about $35. I use the Raspberry Pi to run Nagios and monitor my servers (a tutorial on that will be coming later). I wanted to be able to have my Raspberry Pi send me an SMS message should specific alert happen on my servers, but I really did not want to pay a SMS gateway for this luxury (email works find I would just prefer SMS). So I started looking for a solution.

2014-02-10 09.32.19

I stumbled upon https://github.com/korylprince/pygvoicelib which allowed me to use a simple python script to send SMS messages. The following is how to get your Pi sending text messages with ease.

Step 1: Ensure your Raspberry Pi is setup with your distro of choice and has internet access.

Step2: Sign up for a google voice account
a Gmail account will be needed to do this.

Step3: Enable 2-step verification of your google account.
a link can be found on the following page. https://accounts.google.com/b/0/IssuedAuthSubTokens

Step4: Create an Application Specific password.
Navigate to https://accounts.google.com/b/0/IssuedAuthSubTokens scroll to the bottom and in the name field put “Raspberry Pi” (or whatever other name you want to identify the device). Click on Generate password.

You will then be given a one-time use password.

Step5: Log into your Pi and open the terminal or SSH using Putty
Next cd to your home directory in my case its /home/pi

Code: Select all

cd /home/pi
Step6: Clone the git repository.
First run the following command to prevent SSL errors:

Code: Select all

export GIT_SSL_NO_VERIFY=1
Next run the following command to clone the git repository:

Code: Select all

git clone https://github.com/korylprince/pygvoicelib.git
Step7: Authorize your Raspberry Pi with Google.
cd to the newly created folder pygvoicelib
run the following command:

Code: Select all

python get_auth.py
You will be prompted for your Gmail account and your Application password you got in step 4. After entering the information you will see a number of variables show up in the terminal. Make note of the following variables you will need them in the next step:
username
apppass
auth_token
rnr_se

Step8: Create a script to send a text message.
Run the following command (you can use nano if you wish):

Code: Select all

vi text.py
Place the following code in the file we just created:

Code: Select all

#!/usr/bin/python
import pygvoicelib
number = raw_input(‘number:’)
txtmsg = raw_input(‘message:’)
client = pygvoicelib.GoogleVoice(username,apppass,auth_token,rnr_se)
client.sms(number,txtmsg)


Replace username, apppass, auth_token, and rnr_se with the variable values that were displayed with step 7
Example:

Code: Select all

#!/usr/bin/python
import pygvoicelib
number = raw_input(‘number:’)
txtmsg = raw_input(‘message:’)
client = pygvoicelib.GoogleVoice(‘[email protected]’,'asdfahrwsthjtrh’,’4k3EozF_Qmrg3tD2_m56nQtFHCVSaTdUxb7HvcaN6g3PV929VH0eH4GGVOVpbVK2O6EaGFzMDYA6PhPjaEHr0ZGjO1GQN3RGhQLXqePWfglbXnA2n7XpUophOk5qztQyv2fYM7eYgtVCYeO6txTqbDQAAANsAAABZ7d0GTL2pJsUauPkH4Z3cpbJFqjfLZYfhok1b11pIMDnEOypZgIcOVdPEt8jEMx7oY9hHJeJoDQZYndDJDu8uoDbDWgxl87GMy990snKWR8iy8VIB17769eVWboa3224U8DLZLUWMpP0d4hfsDK5MQ’,'L6tph126BjmNjDcfTZGaWYeb+sk=’)
client.sms(number,txtmsg)




Step8: Send a text message.
Run the following command:

Code: Select all

python text.py
It will prompt you for a phone number and then for the message you wish to send.

Step9: Celebrate
Open a beer and relax

I also have the guide up on my site http://citycorpse.com

User avatar
default_user8
Posts: 658
Joined: Mon Nov 18, 2013 3:11 am

Re: Send SMS Messages from Raspberry Pi

Wed Feb 12, 2014 7:10 pm

Try sms via email
here is a list by provider
Provider Format
Sprint [email protected]
Verizon [email protected]
T-Mobile [email protected]
AT&T [email protected]
AIM +1phonenumber
Two heads are better than one, unless one's a goat head.

User avatar
DougieLawson
Posts: 35594
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Send SMS Messages from Raspberry Pi

Wed Feb 12, 2014 7:31 pm

I don't think using Google Voice to send SMS messages is available outside the US & Canada.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

drgeoff
Posts: 9627
Joined: Wed Jan 25, 2012 6:39 pm

Re: Send SMS Messages from Raspberry Pi

Thu Feb 13, 2014 10:16 am

DougieLawson wrote:I don't think using Google Voice to send SMS messages is available outside the US & Canada.
For 99% of the population of USA and Canada, that is the whole world. :lol:

dgreathouse
Posts: 5
Joined: Wed Feb 12, 2014 3:18 am

Re: Send SMS Messages from Raspberry Pi

Thu Feb 13, 2014 7:33 pm

I understand this will not work for everyone (Sorry if you are outside the United States). A simple SMS gateway can also be used but as Google Voice does not cost anything extra in the states I saw it as a great solution for my use-case. My Raspberry Pi running Nagios is now able to alert me to failed drives on storage units, or failed machines. I am also working on it allowing me to send command replys as a message and with a password being equal execute the command (such as swap a drive).

User avatar
hcunningham
Posts: 43
Joined: Fri Mar 30, 2012 12:07 pm
Location: Sheffield, UK
Contact: Website

Re: Send SMS Messages from Raspberry Pi

Thu Feb 13, 2014 7:47 pm

here's a recipe that works in the UK: http://pi.gate.ac.uk/pages/notipi.html

hth!

Hamish
Mobile power for the Pi Kickstarter Feb 2014: http://tinyurl.com/mobile-pi
Pi.GATE: http://pi.gate.ac.uk/
Hamish Cunningham http://pi.gate.ac.uk/
Mobile and 24/7 power for the Pi: Feb 2014 Kickstarter at http://tinyurl.com/mobile-pi

mn23
Posts: 1
Joined: Tue Jan 28, 2014 3:51 am

Re: Send SMS Messages from Raspberry Pi

Mon Feb 17, 2014 1:35 am

Thanks for the code. I was going along with your instructions and when I put in my username and temp password, this is what I got:
username:myusername
application password:mytemporaryappplicationpassword
Traceback (most recent call last):
File "get_auth.py", line 6, in <module>
client.validate_credentials()
File "/home/pi/pygvoicelib/pygvoicelib.py", line 257, in validate_credentials
self.get_auth_url(None)
File "/home/pi/pygvoicelib/pygvoicelib.py", line 207, in get_auth_url
self._get_auth_token()
File "/home/pi/pygvoicelib/pygvoicelib.py", line 150, in _get_auth_token
raise LoginError('failed', 'Invalid Credentials')
pygvoicelib.LoginError: ('failed', 'Invalid Credentials')

I tried with two different usernames and temp passwords. Any idea what is going on? My application specific username and password is simply the one I created under step 4 right? Thanks so much for the code.

dgreathouse
Posts: 5
Joined: Wed Feb 12, 2014 3:18 am

Re: Send SMS Messages from Raspberry Pi

Thu Feb 20, 2014 6:54 am

Which step did you get the error?

The username is the Gmail email address.

dgreathouse
Posts: 5
Joined: Wed Feb 12, 2014 3:18 am

Re: Send SMS Messages from Raspberry Pi

Wed Feb 26, 2014 6:30 am

On another location where I posted the guide that error was caused by the Gmail account not being properly setup with Google voice.

uguessedit
Posts: 1
Joined: Thu Mar 13, 2014 11:48 pm

Re: Send SMS Messages from Raspberry Pi

Thu Mar 13, 2014 11:51 pm

I'm getting similar error:
Traceback (most recent call last):
File "texter.py", line 13, in <module>
client.sms(number,txtmsg)
File "/usr/local/bin/tide/pygvoicelib/pygvoicelib.py", line 341, in sms
'_rnr_se':self.rnr_se}, mode='raw')
File "/usr/local/bin/tide/pygvoicelib/pygvoicelib.py", line 224, in get_auth_url
raise ServerError(err_code, resp)
pygvoicelib.ServerError: (500, '<HTML>\n<HEAD>\n<TITLE>Internal Server Error</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Internal Server Error</H1>\n<H2>Error 500</H2>\n</BODY>\n</HTML>\n')

Any ideas how to dig deeper?
Thanks

dgreathouse
Posts: 5
Joined: Wed Feb 12, 2014 3:18 am

Re: Send SMS Messages from Raspberry Pi

Wed Mar 19, 2014 9:37 pm

uguessedit wrote:I'm getting similar error:
Traceback (most recent call last):
File "texter.py", line 13, in <module>
client.sms(number,txtmsg)
File "/usr/local/bin/tide/pygvoicelib/pygvoicelib.py", line 341, in sms
'_rnr_se':self.rnr_se}, mode='raw')
File "/usr/local/bin/tide/pygvoicelib/pygvoicelib.py", line 224, in get_auth_url
raise ServerError(err_code, resp)
pygvoicelib.ServerError: (500, '<HTML>\n<HEAD>\n<TITLE>Internal Server Error</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Internal Server Error</H1>\n<H2>Error 500</H2>\n</BODY>\n</HTML>\n')

Any ideas how to dig deeper?
Thanks
Which step did you get this error, I would need to be able to duplicate it to properly troubleshoot it.

korylprince
Posts: 2
Joined: Wed Apr 30, 2014 2:24 am

Re: Send SMS Messages from Raspberry Pi

Wed Apr 30, 2014 2:37 am

Hello all.
I am the owner of that repo. I was pleasantly surprised to find that people are using it.

Unfortunately, Google is going to block unauthorized apps (i.e. us) from using the unofficial Google Voice APIs very soon. I think it will be unlikely that I will be able to find a work-around to this issue.

For more info on this read:
http://www.inquisitr.com/1015175/google ... et-the-ax/
and
https://plus.google.com/u/0/+NikhylSing ... jyncJEbzxK

I have found an alternative, however: http://textbelt.com/

It has an easy enough api:

Code: Select all

$ curl http://textbelt.com/text -d number=1234567890 -d "message=I sent this message for free with textbelt.com"
And you can bring up your own server if you want: https://github.com/typpo/textbelt

It's been fun while it lasted.

Kory

HickoryPi
Posts: 10
Joined: Mon Jan 19, 2015 2:29 pm

Re: Send SMS Messages from Raspberry Pi

Wed Jun 24, 2015 10:10 pm

My pygvoice stopped working within the last several weeks. I get an "HTTP ERROR 404" error returned when trying to generate an SMS. Emails seem to still work fine. Anyone else seeing this?

txt3rob
Posts: 365
Joined: Sat Aug 11, 2012 3:45 pm
Contact: Website

Re: Send SMS Messages from Raspberry Pi

Wed Jul 01, 2015 7:27 am

if you need uk sms my site can offer it as it's sent via a raspberry pi :) http://www.smspi.co.uk
The Raspberry Pi Hell Guy - Random Ramblings to assist me and others.
http://raspberrypihell.blogspot.com
My Github - http:/www.github.com/random-robbie/
http://www.smspi.co.uk - send free uk sms via your raspberry pi from here

HickoryPi
Posts: 10
Joined: Mon Jan 19, 2015 2:29 pm

Re: Send SMS Messages from Raspberry Pi

Thu Jul 02, 2015 3:31 pm

Thank you I am in the US. I use my PI to monitor my home smoke detectors. The system SMS's me when the alarms go off. I was able to get around it by sending an email to my tmobile phone and tmobile converts it into an SMS. Not a direct solution but it seems to work ok. //MIKE

fandiaye
Posts: 20
Joined: Tue Oct 06, 2015 12:44 am

Re: Send SMS Messages from Raspberry Pi

Mon Dec 28, 2015 1:46 am

so I've been trying the tutorial and got my application password, then I ran python get_auth.py and this is the error I get:

username:[email protected]
application password:sdnzixvwdczogwiz
Traceback (most recent call last):
File "get_auth.py", line 6, in <module>
client.validate_credentials()
File "/home/pi/pygvoicelib/pygvoicelib.py", line 257, in validate_credentials
self.get_auth_url(None)
File "/home/pi/pygvoicelib/pygvoicelib.py", line 207, in get_auth_url
self._get_auth_token()
File "/home/pi/pygvoicelib/pygvoicelib.py", line 137, in _get_auth_token
raise LoginError('unknown', "HTTP Error %d" % (err_code))
pygvoicelib.LoginError: ('unknown', 'HTTP Error 404')

I've tried different app passwords but nothing so far except the same error message. Does anybody know or have any idea what the problem could be?
Thanks in advance

pivoron
Posts: 6
Joined: Thu Apr 30, 2015 2:06 am

Re: Send SMS Messages from Raspberry Pi

Thu Dec 31, 2015 6:29 pm

I use node-red (already installed with Raspian Jessie). Built-in is a node for sending SMS! Works for me.
:lol:

closerwalk
Posts: 1
Joined: Fri Jan 08, 2016 10:28 pm

Re: Send SMS Messages from Raspberry Pi

Fri Jan 08, 2016 10:32 pm

If interested I created a sms plugin for nagios based on textbelt sms. (free key word)

https://github.com/closerwalk/send_textbelt_sms

albert007_d
Posts: 22
Joined: Wed Oct 12, 2011 3:52 am

Re: Send SMS Messages from Raspberry Pi

Mon Jan 11, 2016 2:05 pm

http://albert-david.blogspot.com/2016/0 ... m-sim.html
Here is ready to use raspi-Image that make your raspi act as a sms-gateway and you could read/write/delete smsvia xmpp jabber client.
In this case, raspi acts as a xmpp-chatbot allowing you to remotely manage your GSM Sim card.
for details, you can refer to the following post.
viewtopic.php?f=41&t=131481

fandiaye
Posts: 20
Joined: Tue Oct 06, 2015 12:44 am

Re: Send SMS Messages from Raspberry Pi

Sat Jan 23, 2016 6:15 pm

korylprince are you saying this tutorial can't possibly work anymore because of the changes google made? If that's the case then it makes sense because I haven't been able to make it work at all, I just get error messages when I put username and password

albert007_d
Posts: 22
Joined: Wed Oct 12, 2011 3:52 am

Re: Send SMS Messages from Raspberry Pi

Tue Jan 26, 2016 8:32 pm

fandiaye:
did you try the following?
in google's security settings, set "Allow less secure apps: ON"
in my case, by doing so, my xmpp chat-bot is able to login using gmail account.

korylprince
Posts: 2
Joined: Wed Apr 30, 2014 2:24 am

Re: Send SMS Messages from Raspberry Pi

Wed Feb 24, 2016 1:27 am

The ClientLogin API finally stopped working some time in 2015. It's possible someone could use the OAuth 2.0 API to still use the google voice library, but I'm really not sure.

barry914
Posts: 48
Joined: Sat Aug 20, 2016 7:40 pm

Re: Send SMS Messages from Raspberry Pi

Mon Sep 26, 2016 3:19 pm

korylprince wrote:Hello all.
I am the owner of that repo. I was pleasantly surprised to find that people are using it.

Unfortunately, Google is going to block unauthorized apps (i.e. us) from using the unofficial Google Voice APIs very soon. I think it will be unlikely that I will be able to find a work-around to this issue.

For more info on this read:
http://www.inquisitr.com/1015175/google ... et-the-ax/
and
https://plus.google.com/u/0/+NikhylSing ... jyncJEbzxK

I have found an alternative, however: http://textbelt.com/

It has an easy enough api:

Code: Select all

$ curl http://textbelt.com/text -d number=1234567890 -d "message=I sent this message for free with textbelt.com"
And you can bring up your own server if you want: https://github.com/typpo/textbelt

It's been fun while it lasted.

Kory
Amazon offers AWS, a free service for generating text and email messages. Well, it's free for a year for something like 100 text messages per month, and usage charges after a year or if you go over the limit are insignificant. I have not tried it in an RPi environment, but I have been using it with Arduino IoT devices for a couple of years. Accessed via HTML, the data is encrypted and secure. You can take a look at Adafruit's SMS Dog Food Bowl as a guide to porting AWS to RPi. If I were smarter and more motivated I'd try it myself, but ...

User avatar
Nfarrow
Posts: 47
Joined: Sat Dec 20, 2014 1:24 am
Location: Oklahoma, USA
Contact: Website Facebook Twitter YouTube

Re: Send SMS Messages from Raspberry Pi

Sat Dec 24, 2016 4:05 am

Would be cool if someone could build a textbelt server image. So all we would have to do is edit a config file and be up and live.
Twitter: @farrownick
Instagram veggievampire
I own a lot of Pis....

pinkesh
Posts: 1
Joined: Mon Jan 22, 2018 8:28 am

Re: Send SMS Messages from Raspberry Pi

Mon Jan 22, 2018 8:31 am

hello everyone,

I need to send the temp, humidity data collected from sense hat and to send on sms. Is there any free sms gateway available for europe? Which is better way? Can any one also suggest python code?

Return to “Advanced users”