Skip to content

Instantly share code, notes, and snippets.

@rickyrobinett
Last active August 29, 2015 14:02
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickyrobinett/04165da47bc8f60190c5 to your computer and use it in GitHub Desktop.
Save rickyrobinett/04165da47bc8f60190c5 to your computer and use it in GitHub Desktop.
var account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var auth_token = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
var twilio_num = "5558675309";
var number = "55555555555"; // The number you want to text the information to
var client = require('twilio')(account_sid, auth_token);
var accel = require("accel-mma84").use(tessel.port["A"]);
var last_movement = 0.0;
var last_movement_time = Date.now();
// Initialize the accelerometer.
accel.on("ready", function () {
// Stream accelerometer data
accel.setOutputRate(1.56, function rateSet() {
accel.setScaleRange( 8, function scaleSet() {
accel.on("data", function (xyz) {
if( last_movement !== xyz[0].toFixed(1) ) {
last_movement = xyz[0].toFixed(1);
var minutes = ( (Date.now() - last_movement_time)/1000) / 60 ;
last_movement_time = Date.now();
if( minutes > 5 ) {
// send text
sendText( number, twilio_num, "Dog slept for " + Math.round( minutes ) + " minutes");
}
}
});
});
});
});
accel.on("error", function(err){
console.log("Error:", err);
});
function sendText(to,from,msg) {
client.sms.messages.create({
to: to,
from: from,
body:msg
}, function(error, message) {
if (!error) {
console.log('Success! The SID for this SMS message is:');
console.log(message.sid);
console.log('Message sent on:');
console.log(message.dateCreated);
} else {
console.log('Oops! There was an error.', error);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment