Triggering SMS And Voice Notifications For IoT Devices
Time to read: 2 minutes
People throw around the term “the internet of things” as if there’s an internet essence in all devices that you unlock via secret code. The truth is connecting one device to another and building a truly awesome bit of IoT hacking takes some engineering. But after that engineering you get sofas vibrating to music, and IoT connected boxing gloves.
Getting up and running with connected IoT devices isn’t as simple as setting up your dev environment. Marc Pous of TheThings.io knows that, and hopes his platform can take some of that work off of devs’ plates so they can focus on shipping code.
TheThings.io helps you manage those nagging dependencies, interoperability worries, and libraries. It also gives you monitoring reports and data analytics. So if you need to monitor your sofa that vibrates based on the vibe of a music festival, you can do that. Or if you need to get data from the Electric Imp installed inside the boxing glove you outfitted with a force sensor to see who punches the hardest, you can do that too.
For now, we’ll focus on setting up SMS alerts for IoT devices. Let’s say you have a trigger set for temperature monitoring. If your device gets too hot, you’ll get a text or call so you can tend to the issue immediately. In the following example, originally published on TheThings.io’s blog, they’ll show you how to set that up. (Read their original blog post here)
Let’s Get Coding
You’ll need to have a TheThings.io account and a Twilio account to make this jam work. Once you’ve got both of those things sorted, go to the Cloud Code feature on TheThings.io and click on the ‘Cloud code’ link at the left sidebar.
Create a trigger at the ‘Add Trigger‘ button. A form to create a trigger will appear. You have to name the trigger, link it to a product and insert the Javascript code that will be executed.
Triggers are executed when an event occurs like a thingWrite (when your thing post a value). So, we are going to code a script that sends an SMS when the temperature of a thing is up to 50. Here there is the JS code:
Blam, now you have SMS and Voice alerts in 32 lines of Javascript.
If you prefer to receive a voice call instead an SMS, you only have to change the twilio.sendMessage to twilio.makeCall as in the following example:
Here are a few resources if you need any help getting this up and running.
Twilio API & Docs
Learn more about cloud code
Learn more about triggers
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.