forked from my-electronics-lab/rpi-led-local-server-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (29 loc) · 1010 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var express = require('express');
var app = express();
var path = require('path');
var gpio = require('rpi-gpio');
gpio.setup(7, gpio.DIR_OUT);
app.use(express.static(path.join(__dirname, 'public')));
console.log(path.join(__dirname, 'public'));
app.get('/', function(req, res){
res.sendFile(path.join(__dirname + '/views/index.html'));
});
app.post('/led/on', function(req, res){
gpio.write(7, true, function(err) {
if (err) throw err;
console.log('Written True to pin');
console.log(path.join(__dirname, 'public'));
return res.sendFile(path.join(__dirname + '/views/index.html'));
});
});
app.post('/led/off', function(req, res){
gpio.write(7, false, function(err) {
if (err) throw err;
console.log('Written False to pin');
console.log(path.join(__dirname, 'public'));
return res.sendFile(path.join(__dirname + '/views/index.html'));
});
});
app.listen(3000, function () {
console.log('Simple LED Control Server Started on Port: 3000!')
})