Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ReidCarlberg/8910157 to your computer and use it in GitHub Desktop.
Save ReidCarlberg/8910157 to your computer and use it in GitHub Desktop.
var i2c = require('i2c');
var device1 = new i2c(0x18, {device: '/dev/i2c-1', debug: false});
device1.setAddress(0x4);
var AckCounter = 0;
var nforce = require('nforce');
var http = require('http'),
faye = require('faye');
var client;
var outboundMessages = [];
console.log("Welcome to the Thumper interface");
function handleStreamingAPI(_oauth) {
client = new faye.Client(_oauth.instance_url + '/cometd/28.0');
client.setHeader("Authorization", "OAuth " + _oauth.access_token);
var subscription = client.subscribe('/topic/LAB_Device_Messages', function(message) {
var simpleMessageString = "^" + message.sobject.Device_Address__c + ":" + message.sobject.Message__c;
var m = message.sobject.Message__c;
var command = 0;
if (m == 'fstop') {
command = 1;
} else if (m== 'frwrd') {
command = 2;
} else if (m== 'bkwrd') {
command = 3;
} else if (m== 'fleft') {
command = 4;
} else if (m== 'frght') {
command = 5;
} else if (m== 'bleft') {
command = 6;
} else if (m== 'brght') {
command = 7;
} else if (m== 'gslow') {
command = 8;
} else if (m== 'gfast') {
command = 9;
}
device1.writeByte(command, function(err) {
console.log("sent i2c");
console.log(err);
});
console.log(simpleMessageString + "\n");
});
console.log("Streaming API Connected...");
}
function heartbeat() {
AckCounter++;
console.log("Ready and waiting [" + AckCounter + "]");
setTimeout(function() { heartbeat(); }, 10000);
}
var sfuser = "YourUN";
var sfpass = "passwordSECURITYTOKEN";
var query = 'SELECT Id, FirstName, LastName, Email FROM Lead LIMIT 10';
var org = nforce.createConnection({
clientId: '555clientID',
clientSecret: '555clientSecret',
redirectUri: 'http://localhost:3000/oauth/_callback'
});
console.log("Authenticating with Salesforce");
org.authenticate({ username: sfuser, password: sfpass}, function(err, oauth) {
if(err) {
console.error('unable to authenticate to sfdc');
console.log(err);
process.exit(code=0);
} else {
console.log("authenticated");
console.log("oauth");
console.log(oauth);
handleStreamingAPI(oauth);
heartbeat();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment