Created
June 16, 2018 19:29
-
-
Save joeheyming/2848b2f55de1fc94a6f040d404f9a79d to your computer and use it in GitHub Desktop.
garage door app
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
//Requires | |
const express = require('express'); | |
const app = express(); | |
const path = require('path'); | |
const chalk = require('chalk'); | |
const { exec } = require('child_process'); | |
const morgan = require('morgan'); | |
//Static Routes | |
app.use('/dist', express.static(path.join(__dirname, 'dist'))); | |
app.use(morgan('dev')) // logging | |
//Main App Route | |
app.get('/', (req, res, next) => res.sendFile(path.join(__dirname, 'index.html'))); | |
const port = 80; | |
//Run Server | |
app.listen(process.env.PORT || port, () => console.log(chalk.blue(`Listening intently on port ${port}`))); | |
const lookup = [7, 0]; | |
const gpio = '/usr/local/bin/gpio'; | |
function press(door) { | |
console.log('door: ', door); | |
const io = lookup[door]; | |
console.log('io = ', io); | |
exec(`${gpio} write ${io} 1`, (err, stdout, stderr) => { | |
setTimeout(() => exec(`${gpio} write ${io} 0`), 100); | |
}); | |
} | |
app.get('/open/:door', (req, res) => res.send('OK') && press(req.params.door)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment