Building an alarm system with and VoxSMS API (in under 5 minutes)

We recently released our SMS API that enables you to send and receive SMS to your mobile number. We wanted to play around with it at a recent hackathon we organised internally and teamed it with some modules  (that Mike Dauphinais and I won at the previous TADHack in Lisbon).
The result? An alarm system that alerts you by SMS whenever there is someone (or something!) in your house. Now, don’t run to your coffee machine just yet – this takes under 5 minutes!
The hack is not tricky at all and requires just a few lines of actual code. Most of this tutorial covers terminal commands you need to run in order to get this running! Full code available on Github
Here it is! How to build an alarm system with Tessel modules and VoxSMS API!

1. Setting up your express app

If you have express (and express-generator) set up on your machine, just run:

express alarmbot
cd alarmbot && npm install
npm install express --save
npm install express-generator -g
then run (assuming you have nom/node installed)
express alarmbot
cd alarmbot && npm install
Most of what is installed is clutter but at least we’ve got a great base to work with!
You can start your skeleton app with
npm start

2. Setting up

More information on how to set up Tessel on your machine can be found in this starter guide.

3. Setting up the dependencies in your app

To install the Infrared module in your app:
cd alarmbot
npm install ir-attx4
Then add the module dependencies to app.js
var tessel = require('tessel');
var infraredlib = require('ir-attx4');
var infrared = infraredlib.use(tessel.port['A']);
To install the VoxSMS dependencies in your app:
cd alarmbot
npm install voxbone-voxsms
Then add the VoxSMS dependencies to app.js:

a. Add the dependency to your application

var Voxbone = require(‘voxbone-voxsms');

b. Add your credentials

var api_login = 'login';
var api_password = 'password';

c. Create a new Voxbone object for authentication

var voxbone = new Voxbone({
apiLogin: api_login,
apiPassword: api_password

d. Set your SMS settings/number/message etc…

var from = "+3228080438"; //a Voxbone number enabled for VoxSMS (format: +3200000)
var to = "3222222222"; //the destination number (format: 3200000)
var dr = "none"; //Delivery reports - Accepted values: success, failure, all, none

You can now send an SMS wherever you want in the app! Let’s send one when we receive data from the IR module:

infrared.on('data', function(data) {
// If we get data, print it out...
console.log("Received RX Data: ", data);

//and send an SMS!
var msg = “Hey! Someone’s in your house!";
var fragref = voxbone.createFragRef();
voxbone.sendSMS(to, from, msg, fragref, dr);

4. Run your app!

Phew! That was easy, you can now run your app with the following command:
tessel run app.js

There you go! You’ve just created a great alarm system in a few minutes. Now you can go grab some good coffee and enjoy the rest of the day feeling fulfilled and accomplished, but mostly safe!