-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
48 lines (43 loc) · 1.18 KB
/
app.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
47
48
var http = require('http');
var express = require('express');
var app = express();
var gpio = require("pi-gpio");
app.get('/on/:pin', function(req, res) {
gpioPin = req.params.pin;
gpio.close(gpioPin);
gpio.open(gpioPin, "output", function(err) {
gpio.write(gpioPin, 1, function() {
console.log('Pin '+ gpioPin +' is now HIGH.');
res.sendStatus(200);
});
});
});
app.get('/off/:pin', function(req, res) {
gpioPin = req.params.pin;
gpio.close(gpioPin);
gpio.open(gpioPin, "output", function(err) {
gpio.write(gpioPin, 0, function() {
console.log('Pin '+ gpioPin +' is now LOW.');
res.sendStatus(200);
});
});
});
app.get('/blink/:pin/:time', function(req, res) {
gpioPin = req.params.pin;
time = req.params.time;
gpio.close(gpioPin);
gpio.open(gpioPin, "output", function(err) {
gpio.write(gpioPin, 1, function() {
console.log('Pin '+ gpioPin +' is now HIGH.');
});
setTimeout(function() {
gpio.write(gpioPin, 0, function() {
console.log('Pin '+ gpioPin +' is now LOW.');
res.sendStatus(200);
gpio.close(gpioPin);
});
}, time);
});
});
app.listen(3000);
console.log('App Server running at port 3000');