Gavin Dinubilo
Published

Text Messaging Door Bot

A Pinoccio and Node.js powered door bot that will TEXT you when someone rings the doorbell

Full instructions provided1,046
Text Messaging Door Bot

Story

Read more

Code

file_5911.txt

JavaScript
    var client = require('twilio')('{{ sid token }}', '{{ auth token }}');

var pinoccio = require('pinoccio');

var api = pinoccio("{{ pinoccio api token }}");

var s = api.sync();

s.on('data', function(data) {
    data = data.data;
    if (data.type === 'digital' && data.troop === '1' && data.scout === '1') {
        if (data.value.state[0] == 0) {
            console.log("Someone rang the doorbell");
            command = "led.green delay(5000) led.off";
            // initialize the command that we will set below.
            client.sendMessage({

                to: '+{{ your phone number }}', 
                // Any number Twilio can deliver to
                from: '+{{ twilio phone number }}', 
                // A number you bought from Twilio and can use f
                // or outbound communication
                body: '\nword to your mother.\nsomeone rang the doorbell.'
                // body of the SMS message
            }, function(err, responseData) { 
              //this function is executed when a response is received 
              // from Twilio

                if (!err) { 
                  // "err" is an error received during the request, if any
                  // "responseData" is a JavaScript object containing 
                  // data received from Twilio.
                  // A sample response from sending an SMS message is 
                  // here (click "JSON" to see how the data appears in
                  // JavaScript):
              // http://www.twilio.com/docs/api/rest/sending-sms#example-1
                    console.log(responseData.from); 
                    // outputs your twilio number
                    console.log(responseData.body);
                    // outputs the body of the text from above
                }
            });
            api.rest({
                url: "/v1/1/1/command",
                data: {
                    command: command
                }
            }, function(err, data) {});
        }
    }
});

Credits

Gavin Dinubilo

Gavin Dinubilo

8 projects • 7 followers

Comments

Add projectSign up / Login