Created
April 1, 2015 13:17
-
-
Save sidwarkd/a9f639f44b078111c448 to your computer and use it in GitHub Desktop.
Competitor to the Amazon Dash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"sparkAccessToken": "", | |
"sparkDeviceID": "", | |
"twilioAccountSID": "", | |
"twilioAuthToken": "", | |
"toPhoneNumber": "[NUMBER TO CALL]", | |
"fromPhoneNumber": "[YOUR TWILIO NUMBER]", | |
"paperTowelTwiml": "[URL TO TWIML FILE. DROPBOX WORKS GREAT]" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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