Skip to content

Instantly share code, notes, and snippets.

@geersch
Created Sep 3, 2014
Embed
What would you like to do?
Tessel: test of toggling a relay through a HTTP request
var tessel = require('tessel');
var relaylib = require('relay-mono');
var http = require( 'http' );
var myIP = require('my-ip');
setTimeout( function() {
var relay = relaylib.use(tessel.port['A']);
relay.on('ready', function relayReady () {
console.log('Relays ready...');
var server = http.createServer(function (req, res) {
relay.toggle(1, function toggleOneResult(err) {
if (err) {
console.log("Err toggling 1", err);
}
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end();
});
});
server.listen(80);
console.log(myIP());
console.log('Listening on port 80...');
});
}, 10000 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment