Hardware Reference
In-Depth Information
Phoning the Thermostat
You put a lot of work into the last
project. Fortunately, you get to reuse it
in this project. You're going to keep the
hardware exactly the same, but change
the software in order to build an interface
that lets you call the thermostat on the
phone, hear the temperature and status
by voice, and set the thermostat with your
phone keypad.
MATERIALS
» Completed Project 27
» Twilio account
Luba is a bit of a luddite when it comes to new tech-
nologies, and she's not really fond of the mobile web
interface for the thermostat. “But it's a phone!”, she
complains. “Couldn't I just call someone and have
them stop by to change the temperature?” It's a fair
point: if you've got a phone, you should be able to
make things happen with a phone call.
If you've called an automated help service in the last few
years, chances are you were talking to a SIP server. When
you spoke, it tried to recognize your words using speech-
to-text software, or it directed you to touch numbers on
your keypad using text-to-speech software. When you
entered numbers or words, it translated your input into
HTTP GET or POST requests to query a remote server or
local database. When it got results, it read those back to
you using text-to-speech again. If it couldn't understand
what you were saying (perhaps you were screaming
“Operator! Operator! Give me a human being!” as I often
do), it rerouted your call to a number where a human
would answer.
IP-based telephony has taken leaps and bounds in the
last several years, to the point where the line between
a phone call and a web page is very blurry. Server
applications such as Google Voice and Asterisk are
like virtual switchboards—they connect the public
switched telephone network ( PSTN ), and the Internet.
These servers use a protocol called Session Initiation
Protocol , or SIP , to establish a connection between
two clients and determine what services they are
capable of sending and receiving. For example, a SIP
client might be able to handle voice communications,
text messages, route messages to other clients, and
so forth. Sometimes a SIP server sets up the con-
nection between the clients, then gets out of the way
and lets them communicate directly. Other times it
manages the traffic between them, translating the
protocols of one into something that the other can
understand. It's the 21st-century version of the old
switchboard operators. When application designers
have done their job right, you never need to know
anything about SIP, because your phone or software
just tells you what it can do, and provides you a way
to address other people. The phone does this by pre-
senting you with a dial tone and a keypad.
For this project, you're going to use a commercial SIP
service from Twilio to make a voice interface to the ther-
mostat you just built. Twilio provides a variety of Voice
over IP ( VoIP ) services like voicemail, conference calling,
and more. With their commercial accounts, you can buy
phone numbers to which you attach these services, so
your customers can call your service directly. They also
have a free trial service. With the free service, you must
use the phone number they assign to you, and you have
to use a passcode to access your application once you've
called in. For readers outside the U.S. and Canada, Twilio
offers only U.S./Canada-based numbers at the time of this
writing. Read on to get the general idea, then find an equiv-
alent service that works in your country. Phone number
exchange is unfortunately one place the PSTN lags con-
siderably behind the Internet, mostly for commercial and
political reasons. If you really want to get deep into VoIP
and SIP, check out Asterisk: The Future of Telephony by
Jim Van Meggelen, Jared Smith, and Leif Madsen (O'Reilly).
X
Search WWH ::




Custom Search