“Easy” SMS with Twilio

Twilio allows you to send SMS to both send and receive messages from users with nothing more than a flip phone. SMS doesn’t require configurations the way wifi does, and generally works almost anywhere. Twilio allows you to create simple, but powerful, scripts for everything from notifications to full fledged administration.

Slide Notes:

“Easy” Twilio for SMS

Intro to Twilio

  • SMS IaaS
    • IoT is NOT just TCP/IP
    • SMS is most accessible communication system globally 
  • PAIN in the BUTT
    • Documentation Stinks
  • Allows you to extend communication to SMS devices 
  • 19705980147

IoT Beyond TCP/IP

  • TCP/IP is power intensive
  • TCP/IP is prone to attacks
  • TCP/IP requires configuration and maintenance
  • TCP/IP is short distance

Twilio Communication Diagram

Twilio Account

SMS Webhook

Languages for Twilio

Basic Twilio Setup on Digital Ocean

  • Basic Ubuntu Droplet on DigitalOcean
  • Apt update
  • Apt upgrade
  • Sudo apt-install python3-pip
  • Pip3 install twilio

TwilML

Sending Text’s from Python

Parse and Respond to Inbound Text

Python Trigger Script

Opt Out

Prices

Code:

twilio.py

This code allows you to send a text message from your python script.

In Ubuntu make sure to setup the enviornment:

  • Apt update
  • Apt upgrade
  • Sudo apt-install python3-pip
  • Pip3 install twilio
from twilio.rest import Client account_sid = "ACa5db7d403595580275db6ba5d85e3666" auth_token = "935f20e2bc477fc7da277d9cd7adb666" client = Client(account_sid, auth_token) message = client.messages.create( to="+12223334444", from_="+19705980147", body = " this is a test") print(message.sid)
Code language: JavaScript (javascript)

sms_parse.php

Used to parse incoming SMS messages. This message replies to the sender, and saves a comand to a file so the Raspberry Pi can read the command and take an action.

<?php $number = $_POST['From']; $body = $_POST['Body']; $pic = "https://media.vanityfair.com/photos/59653e9a3a5a726a87a6302d/master/pass/Idris-Elba.jpg"; header('Content-Type: text/xml'); ?> <Response> <Message> Hello <?php echo $number ?>. You said <?php echo $body ?> <?php file_put_contents("message.php", $body); ?> <Media><?php echo $pic ?></Media> </Message> </Response>
Code language: HTML, XML (xml)

Raspberry Pi Python Script

This script reads the command in the message.php file on your public web server and then turns a relay on or off.