Skip to content

Instantly share code, notes, and snippets.

@kevinold
Created June 3, 2014 17:21
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 kevinold/fe43dad83b6f873c61a1 to your computer and use it in GitHub Desktop.
Save kevinold/fe43dad83b6f873c61a1 to your computer and use it in GitHub Desktop.
var Spark = require("../lib/spark");
var five = require("johnny-five");
var board = new Spark({
token: process.env.SPARK_TOKEN,
deviceId: process.env.SPARK_DEVICE_ID
});
//require the Twilio module and create a REST client
var client = require('twilio')(process.env.TWILIO_SID, process.env.TWILIO_AUTH_TOKEN);
board.on("ready", function() {
console.log("CONNECTED");
board.analogRead("A7", function(data) {
//console.log( "A7", data );
var voltage = (data * 3.33)/4095;
var celsius = (voltage - 0.5) * 100;
//console.log( "celsius: ", celsius);
var f = celsius * (9/5) + 32; // true c to f forumula
f = f + 29; // hack to get sensor working (add 29 so it is correct)
console.log( "The temperature is: ", f);
// I would like to read the temp once and send to sendTemp() for posting to twilio
// I have 2 ideas:
// 1) manually like I have here (although it reads multiple times; multiple texts via twilio)
// 2) child process for sendTemp() call
// 3) ???
sendTemp(f);
process.exit(0);
});
});
function sendTemp(f) {
//Send an SMS text message
client.sendMessage({
to: process.env.TWILIO_TO_NUM, // Any number Twilio can deliver to
from: process.env.TWILIO_FROM_NUM, // A number you bought from Twilio and can use for outbound communication
body: 'Temp is: ' + f // body of the SMS message
}, function(err, responseData) { //this function is executed when a response is received from Twilio
console.log('in callback');
console.log(err);
if (!err) { // "err" is an error received during the request, if any
console.log(responseData.from); // outputs "+14506667788"
console.log(responseData.body); // outputs "word to your mother."
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment