Skip to content

Instantly share code, notes, and snippets.

@kevinohara80
Last active December 11, 2015 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinohara80/4582566 to your computer and use it in GitHub Desktop.
Save kevinohara80/4582566 to your computer and use it in GitHub Desktop.
Poll my home server so I know when the power is restored at my house. Alert me via text message. Written in node.js.
{
"name": "pollhouse",
"version": "0.0.0",
"description": "Poll my house, let me know when power is on",
"main": "poll.js",
"dependencies": {
"request": "~2.12.0",
"optimist": "~0.3.5",
"mailer": "~0.6.7"
}
}
var argv = require('optimist').argv;
var email = require('mailer');
var request = require('request');
var time = (argv.t) ? argv.t * 60000 : 60000;
var endpoint = argv._[0];
console.log('starting poller');
console.log('polling: ' + endpoint);
function sendText() {
console.log('sending text');
email.send({
ssl: true,
host : 'smtp.gmail.com',
port : 465,
domain : '[127.0.0.1]',
to : '**********@vtext.com', //verizon
from : process.env.GMAIL_USER,
subject : null,
body: 'Your power is back on yo!!!',
authentication : 'login',
username : process.env.GMAIL_USER,
password : process.env.GMAIL_PASS,
debug: false
},
function(err, result){
if(err) {
console.log('unable to send text');
console.log(err.message);
} else {
console.log('text sent');
}
});
}
setInterval(function() {
console.log('attempting to contact host');
request({ uri: endpoint, timeout:6000 }, function(err, res, body) {
if(!err) sendText();
else console.log('could not reach host. aborting.');
});
}, time);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment