On Github hybridgroup / cylon-workshop-2014
var cylon = require('cylon'); cylon.robot({ connection: { name: 'edison', adaptor: 'intel-iot' }, device: { name: 'led', driver: 'led', pin: 4, connection: 'edison' } }) .on('ready', function(my) { setInterval(function() { my.led.toggle(); }, 1000); }) .start();
var cylon = require('cylon'); cylon.robot({ connection: { name: 'edison', adaptor: 'intel-iot' }, device: [ { name: 'led', driver: 'led', pin: 4, connection: 'edison' }, { name: 'touch', driver: 'button', pin: 3, connection: 'edison' }, ] }) .on('ready', function(my) { my.touch.on('press', function() { my.led.turnOn(); }); my.touch.on('release', function() { my.led.turnOff(); }); }) .start();
var cylon = require('cylon'); var robotName = 'cylon01'; var username = 'user'; var password = 'password'; // Paste Cylon.js robot code below this line cylon.robot({ name: robotName, connections: [ { name: 'edison', adaptor: 'intel-iot' }, { name: 'sfcon', adaptor: 'force', sfuser: username, sfpass: password} ], device: [ { name: 'salesforce', driver: 'force', connection: 'sfcon' }, { name: 'led', driver: 'led', pin: 4, connection: 'edison' }, { name: 'touch', driver: 'button', pin: 3, connection: 'edison' }, ] }) .on('ready', function(my) { my.salesforce.subscribe('BoardMsgOutbound', function(err, data) { if (err != null) { console.log(err); } else if (data.sobject.board_id__c === my.name) { if (data.sobject.touch_sensor__c === true) { my.led.turnOn(); } else if (data.sobject.touch_sensor__c === false) { my.led.turnOff(); } } }); my.touch.on('press', function() { var toSend = { boardId: my.name, touchSensor: true }; my.salesforce.post('/Boards/', toSend, function(err, data) { if (err != null) { console.log("Error sending touch sensor information: " + err); } else { console.log('Board Msg has been sent to Salesforce.'); } }); }); my.touch.on('release', function() { var toSend = { boardId: my.name, touchSensor: false }; my.salesforce.post('/Boards/', toSend, function(err, data) { if (err != null) { console.log("Error sending touch sensor information: " + err); } else { console.log('Board Msg has been sent to Salesforce.'); } }); }); }) .start();
var cylon = require('cylon'); var robotName = 'cylon01'; var username = 'user'; var password = 'password'; // Paste Cylon.js robot code below this line cylon.robot({ name: robotName, connections: [ { name: 'edison', adaptor: 'intel-iot' }, { name: 'sfcon', adaptor: 'force', sfuser: username, sfpass: password} ], device: [ { name: 'salesforce', driver: 'force', connection: 'sfcon' }, { name: 'led', driver: 'led', pin: 4, connection: 'edison' }, { name: 'touch', driver: 'button', pin: 3, connection: 'edison' }, { name: 'sensor', driver: 'analogSensor', pin: 0, connection: 'edison' } ] }) .on('ready', function(my) { var ready = false; var sensorVal = 0; my.salesforce.subscribe('BoardMsgOutbound', function(err, data) { if (err != null) { console.log(err); } else if (data.sobject.board_id__c === my.name) { if (data.sobject.touch_sensor__c === true) { my.led.turnOn(); } else if (data.sobject.touch_sensor__c === false) { my.led.turnOff(); } var sensor = data.sobject.analog_sensor__c; if (sensor != null) { console.log("Reading: " + sensor); } } }); my.touch.on('press', function() { ready = true; var toSend = { boardId: my.name, touchSensor: true }; my.salesforce.post('/Boards/', toSend, function(err, data) { if (err != null) { console.log("Error sending touch sensor information: " + err); } else { console.log('Board Msg has been sent to Salesforce.'); } }); }); my.touch.on('release', function() { ready = false; var toSend = { boardId: my.name, touchSensor: false }; my.salesforce.post('/Boards/', toSend, function(err, data) { if (err != null) { console.log("Error sending touch sensor information: " + err); } else { console.log('Board Msg has been sent to Salesforce.'); } }); }); my.sensor.on('analogRead', function(data) { sensorVal = data; }); setInterval(function() { if (ready) { var toSend = { boardId: my.name, touchSensor: true, analogSensor: sensorVal }; my.salesforce.post('/Boards/', toSend, function(err, data) { if (err != null) { console.log("Error sending analog sensor information: " + err); } }); } }, 2000); }) .start();
var cylon = require('cylon'); var robotName = 'cylon01'; var username = 'user'; var password = 'password'; // Paste Cylon.js robot code below this line function writeToScreen(screen, message) { screen.setCursor(0,0); screen.write(message); } cylon.robot({ name: robotName, connections: [ { name: 'edison', adaptor: 'intel-iot' }, { name: 'sfcon', adaptor: 'force', sfuser: username, sfpass: password} ], device: [ { name: 'salesforce', driver: 'force', connection: 'sfcon' }, { name: 'led', driver: 'led', pin: 4, connection: 'edison' }, { name: 'touch', driver: 'button', pin: 3, connection: 'edison' }, { name: 'sensor', driver: 'analogSensor', pin: 0, connection: 'edison' }, { name: 'screen', driver: 'upm-jhd1313m1', connection: 'edison' } ] }) .on('ready', function() { var ready = false; var sensorVal = 0; writeToScreen(my.screen, "Ready!"); my.salesforce.subscribe('BoardMsgOutbound', function(err, data) { if (err != null) { console.log(err); } else if (data.sobject.board_id__c === my.name) { if (data.sobject.touch_sensor__c === true) { my.led.turnOn(); } else if (data.sobject.touch_sensor__c === false) { my.led.turnOff(); } var sensor = data.sobject.analog_sensor__c; if (sensor != null) { var pad = "0000"; var message = "Reading: " + (pad+sensor.toString()).slice(-pad.length); writeToScreen(my.screen, message); console.log(message); } } }); my.touch.on('press', function() { ready = true; var toSend = { boardId: my.name, touchSensor: true }; my.salesforce.post('/Boards/', toSend, function(err, data) { if (err != null) { console.log("Error sending touch sensor information: " + err); } else { console.log('Board Msg has been sent to Salesforce.'); } }); }); my.touch.on('release', function() { ready = false; var toSend = { boardId: my.name, touchSensor: false }; my.salesforce.post('/Boards/', toSend, function(err, data) { if (err != null) { console.log("Error sending touch sensor information: " + err); } else { console.log('Board Msg has been sent to Salesforce.'); } }); }); my.sensor.on('analogRead', function(data) { sensorVal = data; }); setInterval(function() { if (ready) { var toSend = { boardId: my.name, touchSensor: true, analogSensor: sensorVal }; my.salesforce.post('/Boards/', toSend, function(err, data) { if (err != null) { console.log("Error sending analog sensor information: " + err); } }); } }, 2000); }) .start();