Utilizing Twilio and ThingSpeak API in IoT Applications

For this project, we needed a device that detected motion and sent a text message notifying us of the motion via. With the increasing integration of web services and APIs, solutions like this can be further automated from the integration of embedded sensors and connected devices.

We integrated Twilio and ThingSpeak API’s with a Wi-Fi enabled microcontroller and a Passive Infrared Sensor to detect motion and notified us via text message, with the help of Using Revolution11’s Twilio Blog Post, a solution that allows their clients to send small audio/video files and text message via Twilio. They used an HTTPS request and the Insert From URL script step in FileMaker.  For this project, we needed a device that detected motion and sent a text message notifying us of the motion.

twilio_logo_red

Twilio is a cloud communications platform that can send and receive global SMS, MMS, and IP messages from any app, with a simple and powerful API.

Thingspeak

ThingSpeak is an open data platform and API for the Internet of Things (IoT) that enables you to collect, store, analyze, visualize, and act on data from sensors or actuators, such as Arduino, NodeMCU, Raspberry Pi, and other hardware. For example, with ThingSpeak you can create sensor-logging applications, location-tracking applications, and a social network of things with status updates, so you could have your home thermostat control itself based on your current location.

Hardware Summary

  • NodeMCU ESP-12E. The NodeMCU is an open source IoT platform that uses Lua scripting language as well as the Arduino
  • PIR Motion Sensor: Pyroelectric (“Passive”) Infrared Sensor

Software Summary

For this project, we wrote a sketch, the name the program’s code is written to and uploaded onto Arduino boards. The Arduino Sketch was uploaded onto the NodeMCU which uses Twilio and Thingspeak APIs to send notifications by text message when motion was detected.

Steps:

  1. Register for a Twilio account (twilio.com) and get your API Credentials. These will include an [AccountSID] and [AuthToken]
  2. Register for a free ThingSpeak (thingspeak.com)account. We will set create HTTP request with the ThingHTTP app. The ThingHTTP app is meant to simplify device communication with web services and APIs and embedded sensors.
  3. Set up ThingSpeak ThingHTTP Request:

thingspeak

  • Sign into ThingSpeak
  • Click Apps
  • Select ThingHTTP
  • Click Create New Request
  • Enter a Name for your new request: Twilio Test
  • Enter the Twilio Rest API URL:                                                     https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages,json
  • Enter your AccountSid under HTTP Auth Username
  • Enter your Auth Token under HTTP Auth Password
  • Select POST method
  • Enter Content Type: application/x-www-form-urlencoded
  • Under Body enter the required parameters of From, To, and Url:                                         To=+{phonenumber}&From=+{TwilioVerified_Number}&Body={Message}
  • Click Save ThingHTTP and you’ll be given an API Key used in the HTTP request

You can now send your ThingHTTP request and view the response using the following URL:

GET https://api.thingspeak.com/apps/thinghttp/send_request?api_key=thisisyourkey


The PIR_Twilio (download the Sketch)

The Hardware:

NodePIR

When a motion is detected!

Alert

Questions? rapidsystemsengineering.com

1.707.515.0807 • info@rapidsystemsengineering.com

Download a PDF of this blog: Utilizing Twilio and ThingSpeak API in IoT Applications

Utilizing Twilio and ThingSpeak API in IoT Applications

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s