Skip to content

Instantly share code, notes, and snippets.

@chrismatthieu
Forked from zankich/1.js
Created March 12, 2015 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrismatthieu/b4a1d113219b9ffa2390 to your computer and use it in GitHub Desktop.
Save chrismatthieu/b4a1d113219b9ffa2390 to your computer and use it in GitHub Desktop.
// curl -X POST -d '{"devices": "db895340-c344-11e4-9f09-df7578d68eac", "payload": [{"pin":9, "mode":1, "value":1}, {"pin":13, "mode":1, "value":1}]}' http://meshblu.octoblu.com/messages --header "meshblu_auth_uuid: db895340-c344-11e4-9f09-df7578d68eac" --header "meshblu_auth_token: d0a9f0d7e321657a38d25dd492492ffed0baf773"
var Cylon = require('cylon');
Cylon.robot({
connections: {
arduino: { adaptor: 'firmata', port: '/dev/tty.usbmodem1411' },
skynet: { adaptor: 'skynet', uuid: "db895340-c344-11e4-9f09-df7578d68eac", token: "d0a9f0d7e321657a38d25dd492492ffed0baf773" }
},
// devices: {
// p13: { driver: 'direct-pin', pin: 13 },
// p9: { driver: 'direct-pin', pin: 9 }
// },
work: function(my) {
my.skynet.on('message', function(data) {
console.log(data);
// [{"pin":9, "mode":1, "value":1}, {"pin":13, "mode":1, "value":1}]
try{
var payload = JSON.parse(data.payload);
} catch(e){
var payload = data.payload;
}
payload.forEach(function(o) {
var pin = (o.pin).toString();
console.log(my);
// if (my.devices[pin] === undefined) {
// my.device(pin, { driver: "direct-pin", pin: o.pin, connection: "arduino" });
// my.devices[pin].start();
// }
if (my.devices.pin === undefined) {
my.devices.pin = { driver: "direct-pin", pin: o.pin, connection: "arduino" };
my.devices.pin.start();
}
if (o.mode === 0) {
my.devices[pin].digitalRead(function(err, val) {
console.log(val);
});
} else if (o.mode === 1) {
my.devices[pin].digitalWrite(o.value);
}
});
});
}
}).start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment