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

  1. Make sure you have npm and node installed on your machine.
  2. Copy JS below, save to file somewhere on your comp (for ex. '/js/sms-battery.js')
  3. Command line: cd /js/ (or wherever you saved the file)
  4. Command line: npm install node-battery
  5. Command line: npm install twilio
  6. Change accountSid, authToken (mine is there as an example, will be deleted after competition)
  7. Change your phone number, change interval time (25 s) or battery level (20%) check if you want
  8. 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

Built With

Share this project:
×

Updates