How to install Twilio for sending SMS on Yun.

First a little background. I first started working with the Yun board about 4 years ago because I needed to send text message alerts from a project I was working on. After doing some research I found a website that had all the instructions to update Python and its tools and then install Twilio. Worked great and it was easy to incorporate into my code. A couple of years later, Twilio quit working and I never figured out why, but I thought it was something to do with Python. Many hours of trouble shooting and nothing to show for except frustration. I stopped working on that project.

Fast forward to today, and I'm working on this project again. So the first thing was obviously getting Twilio to work again. So, I started doing research on the subject on the intertube and there was a lot of information about the subject, all of it was of no help. So after getting wrapped around the axle, going from one rabbit hole to another and the frustration level rising to epic levels, I decided to contact Twilio and see if they had a solution. I started an email chain with them and showing the log files for all the failures in the installation of the Python tools and they replied that the Twilio installation was failing because the Python tools was an old version that needed to be updated. They were correct but when I updated tools it said everything was up to date. Oh, Joy! In thinking this whole thing over, I was receiving a lot of caution messages that Python was not going to be supported any more and Python3 was going to take its place. Well isn't that special. A little more investigation and I was still drawing a blank.

As thoroughly urinated as I was, i figured that there must be other people having this same problem, so I decided I would come up with a simple fix for this. And, low and behold, I did.

Some pre requisites, Start by upgrading your Yun to latest openwriter software version. I'm not going into the weeds in all this as I'm sure most of you are familiar with this fire drill. Then add some memory by installing an sd card and running the Arduino code to expand it on the board, again, I think you can find it. Next create a swap file so you don't run out of space when you do the installs. One other thing that I found to be helpful is to increase the space on tmpfs to 300 meg.

Now here is the fun stuff that fixed this. I used the command prompt to login to the board and I sent the following commands:

opkg remove python-pip
opkg remove python-setuptools
opkg remove python
opkg install python3-openssl
opkg install python3-pip
opkg install python3-setuptools
python3-pip install twilio

I then sent my first text message and it worked. I almost wet myself I was so surprised!

Also, the way you write your scripts to send a text has changed and so here is what workes for me.

from import Client

Your Account SID from Twilio Cloud Communications | Web Service API for building Voice and SMS Applications

account_sid = 'xxxxxxxx'

Your Auth Token from Twilio Cloud Communications | Web Service API for building Voice and SMS Applications

auth_token = 'xxxxxxx'
client = Client(account_sid, auth_token)
message = client.messages.create(
to='+1 xxxxxxxxxx' ,
from_='+1 xxxxxxxx',
body="Hello from the HomeAutomation Yun! I finally got that sonsabitch")

Ok, boys and girls, there it is. I hope this goes as well for you as it did for me. The only problem going forward is that this works now and that is until some butt hole goes out and changes something in Open Writer or Python that causes it stop working. So much for backward compatibility, but I'm sure that would be too much to ask.

Hello, I have a similar issue using an original Yun version 0(zero). Twilio ran successfully many times until I noticed it did not today when the sketch should have initiated an SMS. I have downloaded the newest zip from twilio but i have a feeling it aint gonna run unless I upgrade to Python 3.0 which from my last recollection isn't compatible with the oldest Yun's. Any hints? Geez this upgrading for an OLD geezer (82) isn't fun and I have a single unit that has to do this from a community well house so it isn't like a production line. I have an 8 GB SD card on the Yun so there is room, but just seems like an enormous amount of overhead to send a twenty character SMS to my Google Voice Number. Thank By the way for the guide above. I have a backup unit I can try stuff on before I go LIVE, so there that possibility.

One solution is to skip Twilio, and send an email instead. Many cellular carriers have an SMS gateway where you can send a properly addressed short email, and it will be delivered as a text message. The address is generally the 10 digit phone number (for USA phone numbers, I don't know how it works in other countries) with a domain that varies per carrier. For the example, to send to a Verizon phone number, it would be A list of some carriers is here (Google can turn up lots of info): [url][/url]

Of course, this turns it into a project of how to send mail, but there are many more options out there compared to a single option with Twilio. It can all be done from the Linux command line, but a little Python or Bash code gives you more options. Google will give you so many ways to do it that the hardest part will be to decide which method to use.

To test it, write a test message on your phone, but send it to your own email address rather than a phone number. Make note of the return address when you receive that email. Then, in your email program, write a short message the other way, sending to that return address from the first test message.

I used to do this, but then found I can set up push email on my phone (I'm using a free iCloud account, but there are others.) This way, I can send a full email that is delivered to my phone almost as fast as a text message, and it gives me full formatting options.

I started with Twillio, quickly went the email to SMS gateway, and finally settled on push email. It's the easiest and most powerful generic notification method I've found yet.

HI SHAPEShifter,
Most grateful for your response. I have a bunch of links set aside to perhaps use php to do the same but had not considered the "vtext" option. I just tried from my gmail, and finally received a test message at (phonenumner) I used to occasionally get the vtext messages so I'll look down that path. I just tried it again from Gmail and although it wasn't instant, i had success.. Seems messages are taking many minutes to work through the web, possibly because my 4G network is spotty and the phone has to be found on My WiFi.
Another consideration i had was to use an IFTTT on my old Galaxy S4 with a prepaid SIM card on Verizon which is the more reliable carrier where we are, but that is more hardware and more apps. (ugh!)
Shapeshifter, your suggestions have always been most reliable, and the email application does seem more doable for an old guy. It would be nice if I can figure out how to do all of it from the Linux side of the Yun. Right now I just trigger a
[Process a;
a.runShellCommandAsynchronously("python /mnt/sda1/");] if I get a low pressure condition at the pump house. Twilio did the rest. The folder on SDA is 100 MB so it won't be missed
We will figure out the alternatives.
Thank YOU again.

Hello All,
Installed ssmtp on the OPENWRT side.
and reconfigured the ssmtp.conf as follows:




IMAP in the gmail account is enabled. CYun is the Yun Name changed in LUCi.
Not caring at this point but the 16 character AuthPass shown but is what Google gave me to use as an APP Password when the 2FA is enabled in gmail.
I tried leaving the "less secure apps access" enabled, and 2FA off, but I get this message no matter what.
" Server didn't like our AUTH LOGIN (530 5.7.0 Must issue a STARTTLS command first."
The several commented lines in or out have not made a difference either.
I am now wondering if Google won't allow non-secured OS to access whether I have the configuration script right or not?
Currently reading:
python-ssl is installed but I'm a novice and have no idea how to use that effectively.

That's entirely possible. GMail is a widespread service that is abused by many people. Google has security practices in place that go far beyond what most other providers require. I don't have any personal experience with GMail, but a couple years ago my work email was routed through Google servers, and it was difficult to get some email clients to work with it. I never tried to get an embedded client to talk to them, but based on my other experiences, I would've expected it to be a battle.

With most services, it's enough to use generic guidance on how to send mail. But with GMail, I think you're going to have to look for programming help from sites that have code specifically tailored for GMail. Yes, I believe it's that different from the generic use case.

Sending SMTP from Yuns. So I am going to put this to bed with the following observation.
I built several system monitors using YUNS that upload a status file to my hosted web portal and the file is displayed in a PHP page and refreshed every 30 seconds or so. I had been using Twilio on the Linux side to relay alarm messages, rare though they may be. Twilio did an upgrade requiring Python 3 which won't run on older Yuns because the Firmware is deprecated. Message feature INOP.

I tried unsuccessfully looking for a suitable method of using the YUN to send SMTP messages through my gmail account instead.
Gmail will not allow any non-authenticated access, with a specially crafted google app password or not. Since there is no practical way to launch a YUN as a DNS listed domain, there can be no authentication.
I then went and bought an email account at GODADDY where I host a simple domain with a web page that displays the conditions at the pump house as discussed above. ( if interested). I discussed my application with the tech support guy at Godaddy so I could get a sense that SMTP would work on the email. Well the email server is OUTLOOK. ( Sadly SMTP from a YUN still doesn't work as there is no domain associated with the message that can be verified on a DNS lookup, secure or not. One can put all kinds of Domains in the config file but the server query cannot confirm the message origin. (as I understand it)
So my solution which, though I am kludgey, really, is to use the phpmail() function on the web server at GoDaddy. I will have the php read or a cron read the uploaded local alarm file and activate the appropriate php script right from the html code. Since everything is happening on the server I see no issues with validation.
Thanks again shapeshifter.

I guess SMTP security is a double-edged sword. You are dealing with the situation where you can't do what you want because the authentication requirements are too strict. The ISP where I host my domains are not as strict, and I don't have trouble sending email from my Yuns. HOWEVER, the other side of that double-edged sword sometimes causes trouble: because their authentication requirements are less strict, spammers/scammers must be able to sometimes get through, because it seems once or twice a year, there is a span of a few days where I'm unable to send mail to AOL users because it gets bounced back due to my ISP's servers not having a good reputation. If AOL thinks that they are getting too much spam from my ISP's servers, they block it for a while and bounce all mail, legitimate or not. So I guess there can be too much security, and not enough security, and each can cause its own problems.

Back when I was using Google's mail servers, I seem to recall that there was a setting in the Google mail preferences that allowed connections from insecure devices. If you tried allowing insecure devices, I recall that there were dire warnings you had to click through. Did you try that (although I'm not sure you really want to do that.) But then again, that might've just been to allow access to read mail through insecure devices, and not send it.

Any way you look at it, and any way it turns out, I'm sorry the idea isn't working out for you and I'm sorry to have caused you more work. :confounded: But at least we all learned something. :+1: :wink:

I have been trying to use twilio from my home network. Gave up when twilio required new Python on an old yun. Instead, I have managed without any big issues to do SMTP email from the Godadddy server that hosts my webpage and associated webmail. The <send_SMTP.php> works now sending messages to my phone or gmail, so that is cool. I believe I can cc: others too.
When my monitor encounters an alarm state I will ftp a text message to the server. I plan to run a cron on the server that looks for those unique messages and triggers python to run the appropriate 'alarm' SMTP e-mail, and then erases the Yun txt file, so only one message is sent. The Yun Monitor sketch limits alarm postings to three, and 'clear' to once. The Cron would send an all clear in the same way. Like I said kludgey. Once I get it up I'll share some code.

  1. When using a free Twilio account, you'll need to verify the phone number to which messages are being sent by going to Twilio and following the instructions under the "Numbers > Verified Caller IDs" tab.

  2. Make sure that you have the latest version of the Arduino IDE. You should also be sure that you have the newest version of the Library by checking the Arduino Library Manager

  3. Make sure that your Yún is connected to the Internet. Arduino has a helpful guide if you need assistance.

More Info :- SMSala Bulk SMS Provider

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.