Created
December 8, 2014 21:01
-
-
Save efexen/c7bcdddaad4db88cdae5 to your computer and use it in GitHub Desktop.
Raspberry Pi & Physical Web LED Demo
This file contains 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
var http = require('http'); | |
var url = require('url'); | |
var piblaster = require('pi-blaster.js'); | |
var beacon = require('uri-beacon'); | |
var ngrok = require('ngrok'); | |
var handlebars = require('handlebars'); | |
var fs = require('fs'); | |
var layout = handlebars.compile(fs.readFileSync('./layout.html', 'utf8')); | |
http.createServer(function (req, res) { | |
var command = url.parse(req.url).pathname.slice(1); | |
res.writeHead(200, { 'Content-Type': 'text/html' }); | |
var data = { | |
text: 'Switch Off', | |
state: 'on', | |
action: 'off' | |
}; | |
if (command === 'on') { | |
piblaster.setPwm(17, 1); | |
} else { | |
piblaster.setPwm(17, 0); | |
data = { | |
text: 'Switch On', | |
state: 'off', | |
action: 'on' | |
}; | |
} | |
res.end(layout(data)); | |
}).listen(80); | |
ngrok.connect(80, function(err, url) { | |
beacon.advertise(url); | |
}); |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Pi LED Demo</title> | |
<meta name="description" content="Physical Web Raspberry Pi LED Demo"> | |
<style> | |
html { | |
background: #222; | |
} | |
a { | |
color: #DBDBDB; | |
text-decoration: none; | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
padding: 2vw 3vw; | |
display: block; | |
border: 2px solid #17A01E; | |
border-radius: 1vw; | |
font-size: 8vw; | |
} | |
a.on { | |
border-color: #A01717; | |
} | |
</style> | |
</head> | |
<body> | |
<a href="{{action}}" class="{{state}}">{{text}}</a> | |
</body> | |
</html> |
This file contains 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
{ | |
"name": "testing_app", | |
"version": "0.0.0", | |
"description": "testing raspberry pi setup", | |
"main": "index.js", | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"handlebars": "^2.0.0", | |
"ngrok": "^0.1.98", | |
"pi-blaster.js": "0.0.2", | |
"uri-beacon": "^0.1.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment