Problem geting ThingHTTP to send sms from Twilio
Show older comments
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
Vinod
on 18 Nov 2020
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.
Sheila Hill
on 18 Nov 2020
Sheila Hill
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 :)
Sheila Hill
on 18 Nov 2020
Sheila Hill
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.
Christopher Stapels
on 19 Nov 2020
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);
Sheila Hill
on 20 Nov 2020
Christopher Stapels
on 20 Nov 2020
Edited: Christopher Stapels
on 8 Dec 2020
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.
Answers (0)
Communities
More Answers in the ThingSpeak Community
Categories
Find more on Act on Data in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!