-
-
Save zankich/9cdccf6878e2fd10bb49 to your computer and use it in GitHub Desktop.
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
// 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(); | |
if (my.devices[pin] === undefined) { | |
my.device(pin, { driver: "direct-pin", pin: o.pin, connection: "arduino" }); | |
} | |
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