Problem geting ThingHTTP to send sms from Twilio

I hate to ask but I have been struggling with this and just can't get it working.
I set up a Twilio trial account and tested it sending an SMS to my cell phone.
I set up a Thingspeak REACT to respond to data in one of my channels and then use ThingHTTP to write data to another channel.
The part I can't get working is for a REACT to use ThingHTTP to get Twilio to send an SMS to my cell. I have read several tutorials and watched videos but just can't get there.
The ThingHTTP screen has the following:
API Key XXXYYYYZZZZ // there is a long key that thingspeak generates - as far as I know I don't use this anywhere
URL https://api/twilio.com/2014-04-01/Accounts/xxxxmynumberyyyy/Messages // have aslo tried ...mynumberyyy/SMS/Messages
HTTP Auth Username XXXXmyTwilioAccountSIDyyyy
HTTP Auth Password XXXmyTwilioAuthTokenyyyy
Method POST
Content Type application/x-www-forms-urlencoded
HTTP Version 1.1
HOST I left this blank
Headers None added
Body From=+15875555555&To=+15875555555&Body=Test Message 1 // not my real hone numbers
Parse String I left this blank
Any pointers would be greatly appreciated.

10 Comments

What cell phone provider are you using?
There is a way to use the "ThingSpeak Alerts" feature to send you SMS alerts instead of going through Twillio with certain carriers, and especially if you don't change your cell phone carrier often.
I have a couple phones in the family - one with Telus and one with Speakout (uses Rogers network) (Canadian eh)
I verified both with Twilio and have sent messages from within twilio so I don't think that is part of the problem. I dismissed the Thingspeak Alerts as it is for sending emails. I want to get a text message not an email. However - your comment says "to send you SMS alerts". So I guess I should look into the Thingspeak Alerts closer.
Thanks for your comment.
I had a look and the Thingspeak Alerts is only for emails. But doing more reading here, I see there is an API key in my user profile. So I would think this would need to be entered somewhere on the ThingHTTP page, but I don't know where. The ThingHTTP has a key API Key: Auto generated API key for the ThingHTTP request
I would think this needs to match the API key on my user profile, but they don't match and I can't edit those entries. I am stumped.
Vinod
Vinod on 18 Nov 2020
Edited: Vinod on 18 Nov 2020
Most (if not all) cell phone providers provide a way to send emails to a phone number that show up on your phone as an SMS. Take a look at this instruction for Rogers.
So, how does this work with ThingSpeak Alerts, you ask?
What I do is set up a Gmail filter so that any alerts coming from ThingSpeak get the rule applied to forward this email to my cell phone number. So, next question is how do I generate the email -- I use the ThingSpeak React app to execute MATLAB code. The MATLAB code makes a request to the ThingSpeak Alerts API when whatever set of conditions you specify in the MATLAB code is met.
Et Voila! SMS alerts from ThingSpeak without needing a middleman :)
Brilliant! I was busy doing more testing and I can get python to get twilio to send an sms. But still can't figure why my React >> ThingHTTP is not working.
But your way of doing this sounds good - no middleman. I have tested sending email to sms with both our cell phones and that works. So now I just need to figure out this MATLAB code to make a request to Thingspeak Alerts API. I have a feeling I will struggle with this - but that is part of the learning. Bonus - I should be able to get one Alert email to gmail forwarded to both our cell phones at the same time.
Thanks for your help. My tests all worked. Just need to do the fine tuning now.
Vinod
Vinod on 19 Nov 2020
Edited: Vinod on 19 Nov 2020
Glad to hear! One thing to keep in mind -- hopefully your algorithm limits itself to fewer than 3 emails per hour. At higher rates, the Alerts feature will return a HTTP 429 (to prevent the service from being used to spam people.)
Also, if you don't mind documenting the steps you took to get this working, it will likely be appreciated by other users who might want to do the same thing.
There is template code in MATLAB analysis that shows how to trigger an alert. Its based on this example.
Here is my code for sending from Twiliio. I know your issue was triggering from react, so I hope this still helps.
Instead of thingHTTP, I would traigger MATLAB analysis code that looks like this.
URL='https://api.twilio.com/2010-04-01/Accounts/<ACCOUNT SID>/Messages.json';
opt = weboptions();
opt.Username = '<ACCOUNT SID>';
opt.Password = '<AUTH TOKEN>';
to = '<PhoneNoToSend>';
from = '<MyTwilioPhone>';
body = 'My Hello from ThingSpeak';
webwrite(URL,'To',to,'From',from,'Body',body, opt);
Thanks Vinod, I hope to send very few emails - ideally none. An alert means I may have to drive several hours to go light a pilot light or fix something else.
Thanks Christopher, posting that detailed code for me did the trick. I set up a react to check for a temperature > 9 and if so, trigger the MATLAB send SMS via Twilio. It works and works very fast!
Another question - maybe I should post separately?? I see a React can easliy be set up to check for "no data". And I specify what channel to check. Is there a way to check individual fields in that channel? If I have several devices sending data to different fields in the same channel, I want to know if one of them stops sending data, even if the others are still sending data.
We reccomend one channel per device for several reasons. One is that asynchronous posts could be within the update frequency and result in lost data. Another is that you get null values in the other fields when a device posts to a shared channel. If you put each device in its own channel, you can then create a summary channel that combines the two channels.
To check individual fields, I would use a MATLAB analysis script and then run it regularly with TimeControl.
thingSpeakRead() lets you specify a field to read from, or you can read a bunch of data and parse it to find missing values.

Sign in to comment.

Answers (0)

Communities

More Answers in the  ThingSpeak Community

Categories

Products

Asked:

on 18 Nov 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!