Background
I forget to charge my laptop sometimes, so I created a module that would txt me when my laptop runs out of battery. I can keep it running in the background and I won't forget to put it on charge again! This only works in OSX and Linux due to node-battery requirements.
Installation
- Make sure you have npm and node installed on your machine.
- Copy JS below, save to file somewhere on your comp (for ex. '/js/sms-battery.js')
- Command line: cd /js/ (or wherever you saved the file)
- Command line: npm install node-battery
- Command line: npm install twilio
- Change accountSid, authToken (mine is there as an example, will be deleted after competition)
- Change your phone number, change interval time (25 s) or battery level (20%) check if you want
- Command line: node sms-battery.js to run ^C to close
Code
var twilio = require('twilio');var nodeBattery = require("node-battery");
var accountSid = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var client = new twilio.RestClient(accountSid, authToken);
setInterval(function () {
nodeBattery.percentages(function(data){
if(data[0]<20){
client.messages.create({
to:'+1 YOUR PHONE NUMBER HERE', //put your phone number in "to"
from:'+1XXXXXXXXXX',
body:'You should charge your laptop now! It has less than 20% battery!'
},
function(error, message) {
if (error) {
console.log(error.message);
}
});
}
});
}, 25000); //Currently checks every 25 seconds, you can change this

Log in or sign up for Devpost to join the conversation.