Skip to content

Instantly share code, notes, and snippets.

@johnnyman727
Created July 27, 2014 18:14
Show Gist options
  • Save johnnyman727/d2133edc30c4fa82abf5 to your computer and use it in GitHub Desktop.
Save johnnyman727/d2133edc30c4fa82abf5 to your computer and use it in GitHub Desktop.
Blink the Tessel LED over WiFi
var http = require('http');
var state = 1;
function toggleLED() {
// Change the IP Address to your Tessel's IP Address!
var path = 'http://172.20.10.5:8080/green/' + state
console.log('getting at', path);
http.get(path, function(res) {
console.log('got this response');
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.once('data', function (chunk) {
console.log('BODY: ' + chunk);
});
state ? state = 0 : state = 1;
toggleLED();
});
}
toggleLED();
var router = require('tiny-router'),
tessel = require('tessel');
var lights = {
green: tessel.led[0],
blue: tessel.led[1],
red: tessel.led[2],
amber: tessel.led[3]
};
router
.get('/', function(req, res) {
res.send('Simple light web API');
})
.get('/lights', function(req, res){
res.send(lights);
})
.get('/green', function(req, res){
var state = lights.green.read();
lights.green.write(state);
res.send({status: state});
})
.get('/green/{state}', function(req, res){
var state = parseInt(req.body.state);
lights.green.write(state);
res.send({status: state});
});
router.listen(8080);
console.log('listening on port 8080');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment