Skip to content

Instantly share code, notes, and snippets.

@geersch
Created Sep 4, 2014
Embed
What would you like to do?
tiny-router controller relays
var tessel = require('tessel');
var relaylib = require('relay-mono');
var router = require('tiny-router');
setTimeout( function() {
var relay = relaylib.use(tessel.port['A']);
relay.on('ready', function relayReady() {
console.log('Relays ready...');
router
.get('relay/state/{relayChannel}', function (req, res) {
var relayChannel = parseInt(req.body.relayChannel);
console.log('getting state of relay channel # ' + relayChannel);
relay.getState(relayChannel, function (err, state) {
res.send({status: state});
});
})
.get('relay/toggle/{relayChannel}', function (req, res) {
var relayChannel = parseInt(req.body.relayChannel);
console.log('toggling relay channel #' + relayChannel);
relay.toggle(relayChannel, function toggleResult (err) {
relay.getState(relayChannel, function stateResult (err, state) {
res.send({status: state});
});
});
});
router.listen(80);
});
}, 10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment