Skip to content

Instantly share code, notes, and snippets.

@mickstevens
Forked from sidwarkd/config.json.sample
Last active August 29, 2015 14:18
Show Gist options
  • Save mickstevens/b1616609b17f7a32fee1 to your computer and use it in GitHub Desktop.
Save mickstevens/b1616609b17f7a32fee1 to your computer and use it in GitHub Desktop.
{
"sparkAccessToken": "",
"sparkDeviceID": "",
"twilioAccountSID": "",
"twilioAuthToken": "",
"toPhoneNumber": "[NUMBER TO CALL]",
"fromPhoneNumber": "[YOUR TWILIO NUMBER]",
"paperTowelTwiml": "[URL TO TWIML FILE. DROPBOX WORKS GREAT]"
}
// A knock-off of the Amazon Dash product using a Spark Core, button, and NodeJS
int button = D0; // Our button
int led = D7; // Really only used for testing to ensure button presses are registering
// This routine runs only once upon reset
void setup() {
Spark.publish("online");
pinMode(button, INPUT_PULLUP); // Enable the internal pullup so no external resistors are required
pinMode(led, OUTPUT);
}
// This routine gets called repeatedly, like once every 5-15 milliseconds.
// Spark firmware interleaves background CPU activity associated with WiFi + Cloud activity with your code.
// Make sure none of your code delays or blocks for too long (like more than 5 seconds), or weird things can happen.
void loop() {
// Check for a button press
if(digitalRead(button) == LOW){
digitalWrite(led, HIGH);
Spark.publish("papertowels"); // This event causes the magic to happen in the monitor app
delay(400);
digitalWrite(led, LOW);
}
}
var spark = require('sparknode');
var fs = require('fs');
//
// Config
//
if (!fs.existsSync('./config.json')) {
console.error('Please create a config.json -- check config.json.sample');
process.exit();
}
var config = require('./config.json');
var client = require('twilio')(config.twilioAccountSID, config.twilioAuthToken);
var core = new spark.Core({
accessToken: config.sparkAccessToken,
id: config.sparkDeviceID
});
core.on('online', function(){
console.log("Congo Mash Button Online!");
});
// These are different events that can be fired by the configured buttons
core.on('papertowels', function(){
client.makeCall({
to:config.toPhoneNumber,
from: config.fromPhoneNumber, // A number you bought from Twilio and can use for outbound communication
url: config.paperTowelTwiml // A URL that produces an XML document (TwiML) which contains instructions for the call
}, function(err, responseData) {
//executed when the call has been initiated.
console.log(responseData.from); // outputs your fromPhoneNumber
if(err)
console.log(err);
});
})
core.on('error', function(data) {
console.error('Error: ' + JSON.stringify(data));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment